Created
May 12, 2016 07:26
-
-
Save euperia/b5bfc8bd4000dc559cf7a5e5780161ce to your computer and use it in GitHub Desktop.
Javascript: forEach over arrays and Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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