Iterating over object properties (v16)

Revision 16 of this benchmark created by Joshua Wise on


Description

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

Setup

var object = {foo: true, bar: null, baz: function(){}, qux: 55, norf: 'string'};

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
for (var key in object) {
  if (object.hasOwnProperty(key)) {object[key];}
}
ready
getOwnPropertyNames
var names = Object.getOwnPropertyNames(object);
for (var i=0, len=names.length; i<len; i++) {
  object[names[i]];
}
ready

Revisions

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