+ 1
ForEach
What is wrong with my forEach method? https://sololearn.com/compiler-playground/Wq0FGYNEjB2k/?ref=app Thanks
3 Answers
+ 2
"divs" is an object, not an array.
you can try this:
const divs=Array.from(document.getElementsByTagName("div"));
if you want to make sure that it runs on sololearn playground, you need to wrap all your JS in
window.onload = () => {
...
}
so that it only grabs rhe html elements when the body is fully loaded.
+ 1
So you mean that a regular for loop will work on objects but not a forEach?
+ 1
forEach an array method. common objects don't have a forEach method