Skip to content

Instantly share code, notes, and snippets.

@nola
Created November 26, 2013 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nola/7652275 to your computer and use it in GitHub Desktop.
Save nola/7652275 to your computer and use it in GitHub Desktop.
JavaScript foreach Loop Shorthand
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
@maheshmarripud
Copy link

hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment