Skip to content

Instantly share code, notes, and snippets.

@zanona
Forked from bendc/nodelist-iteration.js
Created May 20, 2016 12:18
Show Gist options
  • Save zanona/ff3070368a2003d80defa351b5582409 to your computer and use it in GitHub Desktop.
Save zanona/ff3070368a2003d80defa351b5582409 to your computer and use it in GitHub Desktop.
ES6: Iterating over a NodeList
var elements = document.querySelectorAll("div"),
callback = (el) => { console.log(el); };
// Spread operator
[...elements].forEach(callback);
// Array.from()
Array.from(elements).forEach(callback);
// for...of statement
for (var div of elements) callback(div);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment