Each Vs For loop

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var arr = ['a', 'b', 'c', 'd', 'e'];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Each
$.each(arr, function(i, v) {
 if (v == 'e') {
  return v;
 }
});
ready
For
var i, l = arr.length;
for (i = 0; i < l; i++) {
 if (arr[i] == 'e') {
  return arr[i];
 }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.