Skip to content

Instantly share code, notes, and snippets.

@thetallweeks
Last active December 28, 2015 03:09
Show Gist options
  • Save thetallweeks/7433370 to your computer and use it in GitHub Desktop.
Save thetallweeks/7433370 to your computer and use it in GitHub Desktop.
This is a better way to do a for loop. It stores the array length in a variable so the javascript doesn't have to get the array length every iteration.
var names = ['George',
'Ringo',
'Paul',
'John'];
for(var i = 0, j = names.length; i < j; i++) {
doSomethingWith(names[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment