Looping Array of Objects

Benchmark created by Chris on


Setup

var arr = [];
    
    for (var i=0;i<1000;i++) {
      arr.push({
        a:'a',
        b:2,
        c:true
      });
    }

Test runner

Ready to run.

Testing in
TestOps/sec
For...in
for (var i in arr) {
  var thisObj = arr[i];
}
ready
For...in with hasOwnProperty
for (var i in arr) {
  if (arr.hasOwnProperty(i)) {
    var thisObj = arr[i];
  }
}
ready
For
for (var i=0; i<arr.length; i++) {
  var thisObj = arr[i];
}
ready
For - caching length
for (var i=0,len=arr.length; i<len; i++) {
  var thisObj = arr[i];
}
ready
Reverse While
var i = arr.length;
while (i--) {
  var thisObj = arr[i];
}
ready
Native
arr.forEach(function(thisObj) {
  
});
ready

Revisions

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

  • Revision 1: published by Chris on