Skip to content

Instantly share code, notes, and snippets.

@t0mtaylor
Forked from nola/foreachloop.js
Last active August 29, 2015 14:02
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 t0mtaylor/ab07c8b14fa0f8851d15 to your computer and use it in GitHub Desktop.
Save t0mtaylor/ab07c8b14fa0f8851d15 to your computer and use it in GitHub Desktop.
for (var i = 0; i < allImgs.length; i++)
//shorthand
for(var i in allImgs)
//cache
var i, allImgsLen = allImgs.length;
for (i = 0; i < allImgsLen i++)
//quick reverse << FAST!
var i = allImgs.length;
while(i--)
//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