Mozilla states that "for of loops will loop over NodeList objects correctly". (source: https://developer.mozilla.org/en-US/docs/Web/API/NodeList) However, this doesn't work in Chrome 43. Is this incorrect documentation or a browser bug?
The copied example code used on a page with checkboxes:
var list = document.querySelectorAll( 'input[type=checkbox]' );
for (var item of list) {
item.checked = true;
}
You can use
Array.from
or more shortly
Important note
Array.from
was introduced in Chrome 45 source.I had this problem. Turns out mine was caused by calling Promise.all() with parameters instead of an array. For example:
Before:
Promise.all(p1, p2)
After:
Promise.all([p1, p2])
Hope this helps someone.
Native
Symbol.iterator
support forNodeList
was added to the WHATWG's DOM spec in 2014.Unfortunately, Chrome 51 is the first version of Chrome to support it, and its Beta has only just been released at the time of writing this answer. Also, there's no support in any version of Internet Explorer or Edge.
To add
Symbol.iterator
support forNodeList
in all browsers to your code, just use the following polyfill :