DEV Community

HarmonyOS
HarmonyOS

Posted on

[Smart Watch] [API 6] When Using forEach in javaScript, It Keeps Prompting That e.forEach Is Not a Function.

Read the original article:[Smart Watch] [API 6] When Using forEach in javaScript, It Keeps Prompting That e.forEach Is Not a Function.

Question

When displaying data in the interface using a for loop after making a data request in JavaScript, it keeps prompting that:

e.forEach is not a function.Copy codeCopy code
Enter fullscreen mode Exit fullscreen mode

Answer

The data requested using http.createHttp() is a JSON string, and forEach cannot be used on strings. You can use JSON.parse() to convert the string into a JSON object, and then use the forEach function.

Written by Muaz Kartal

Top comments (0)