Skip to content

Instantly share code, notes, and snippets.

@joalbertg
Created February 6, 2018 15:38
Show Gist options
  • Save joalbertg/0280a94a5ab345007897eacd5e09dc86 to your computer and use it in GitHub Desktop.
Save joalbertg/0280a94a5ab345007897eacd5e09dc86 to your computer and use it in GitHub Desktop.
Iterar un nodeList
let 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 (let div of elements) callback(div);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment