Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the JavaScript method array.forEach work in Chrome?

Here's my demo.

I'm trying to get the JavaScript forEach method to work in Google Chrome.
Caniuse hasn't been much help. :(

Any help would be appreciated! Thanks!

like image 878
Web_Designer Avatar asked May 08 '12 05:05

Web_Designer


2 Answers

Convert the NodeList to an array:

nodes = Array.prototype.slice.call(nodes);

Then you can use .forEach() on it.

like image 119
ThiefMaster Avatar answered Nov 07 '22 04:11

ThiefMaster


document.querySelectorAll doesn't return array but a NodeList object which has no method 'forEach'.

The error msg shows you that:

Object #<NodeList> has no method 'forEach'

Check this article, which explains this.

like image 26
xdazz Avatar answered Nov 07 '22 04:11

xdazz