Object Keys Vs For In (v4)

Revision 4 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
For In
var jsonObj = {
  prop1: "abc",
  prop2: "def",
  prop3: "ghi",
  prop4: "jkl",
  prop5: "mno",
  prop6: "pqr",
  prop7: "stu",
  prop8: "vwx"
};
var result = "";
for (key in jsonObj) {
  if (jsonObj.hasOwnProperty(key)) {
    result = result + jsonObj[key];
  }
}
ready
Object.keys for loop
var jsonObj = {
  prop1: "abc",
  prop2: "def",
  prop3: "ghi",
  prop4: "jkl",
  prop5: "mno",
  prop6: "pqr",
  prop7: "stu",
  prop8: "vwx"
};
var result = "",
  keys  = Object.keys(jsonObj);

for (var i = 0, l = keys.length; i < l; i++) {
  result = result + jsonObj[keys[i]];
}
ready

Revisions

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