Skip to content

Instantly share code, notes, and snippets.

@st3v3nhunt
Created May 10, 2011 19:22
Show Gist options
  • Save st3v3nhunt/965186 to your computer and use it in GitHub Desktop.
Save st3v3nhunt/965186 to your computer and use it in GitHub Desktop.
JS for iterator caching
// no caching of iteration size
for (var i=0; i<myArray.length; i++) {}
// caching of iteration size - ugly version
var length = myArray.length;
for (var i=0; i<length; i++) {}
// caching of iteration size - nice version
for (var i=0, len=myArray.length, i< len; i++) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment