Iterating over object properties (v26)

Revision 26 of this benchmark created on


Description

Comparing various approaches to iterating over an object's enumerable properties.

Setup

var object = {};
    for (var i = 0; i < 100; ++i) {
      object['user'+i] = 'user'+i;
    }
    var foo;

Test runner

Ready to run.

Testing in
TestOps/sec
for…in
for (var property in object) {
  if (object.hasOwnProperty(property)) {
    foo = object[property];
  }
}
ready
for…in with continue
for (var property in object) {
  if (!object.hasOwnProperty(property)) continue;
  foo = object[property];
}
ready
Filtering with Object.keys
for (var i = 0, keys = Object.keys(object), l = keys.length; i < l; ++i) {
  foo = object[keys[i]];
}
ready
Object.keys + forEach
Object.keys(object).forEach(function (key) {
  foo = object[key];
});
ready
for…in without checks
for (var property in object) {
  foo = object[property];
}
ready

Revisions

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