Created
November 26, 2013 01:53
-
-
Save nola/7652275 to your computer and use it in GitHub Desktop.
JavaScript foreach Loop Shorthand
This file contains 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
for (var i = 0; i < allImgs.length; i++) | |
//shorthand | |
for(var i in allImgs) | |
//with array | |
function logArrayElements(element, index, array) { | |
console.log("a[" + index + "] = " + element); | |
} | |
[2, 5, 9].forEach(logArrayElements); | |
// logs: | |
// a[0] = 2 | |
// a[1] = 5 | |
// a[2] = 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello