Skip to content

Instantly share code, notes, and snippets.

@jacobarriola
Forked from bendc/nodelist-iteration.js
Created April 6, 2017 20:47
Show Gist options
  • Save jacobarriola/ed27969392b371bcbfe39331d3a3df37 to your computer and use it in GitHub Desktop.
Save jacobarriola/ed27969392b371bcbfe39331d3a3df37 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