Skip to content

Instantly share code, notes, and snippets.

@euperia
Created May 12, 2016 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euperia/b5bfc8bd4000dc559cf7a5e5780161ce to your computer and use it in GitHub Desktop.
Save euperia/b5bfc8bd4000dc559cf7a5e5780161ce to your computer and use it in GitHub Desktop.
Javascript: forEach over arrays and Objects
// forEach over Arrays
var items = ['fish', 'birds', 'dogs', 'cats'];
items.forEach(function(item, index) {
console.log(index + ': ' + item);
});
// forEach over Objects
var h2 = document.getElementsByTagName('h2');
Object.keys(h2).forEach(function(item){
console.log(j2[item]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment