Skip to content

Instantly share code, notes, and snippets.

@duccoder
Last active August 29, 2015 14:01
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 duccoder/70304ac3b3b8b7db90ab to your computer and use it in GitHub Desktop.
Save duccoder/70304ac3b3b8b7db90ab to your computer and use it in GitHub Desktop.
For & Each
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
//array arr
var arr = new Array();
var i=0;
for (i; i<100000; i++) {
arr[i] = i;
}
//use for
console.time('for');
var l = arr.length;
var i=0;
for (i;i<l; i++) {
arr[i] = i;
}
console.timeEnd('for');
//use each
console.time('each');
$.each (arr, function (i) {
arr[i] = i;
});
console.timeEnd('each');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment