Object Keys Vs For In

Benchmark created by Danny on


Setup

var jsonObj = {
      prop1: "abc",
      prop2: "def",
      prop3: "ghi"
      prop4: "jkl"
      prop5: "mno"
      prop6: "pqr"
      prop7: "stu"
      prop8: "vwx"
      prop9: "yz"
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Object.keys
var result = "";
Object.keys(jsonObj).forEach(function(key) {
  result = result + jsonObj[key];
});
ready
For In
var result = "";
for (key in jsonObj) {
  if (jsonObj.hasOwnProperty(key)) {
    result = result + jsonObj[key];
  }
}
ready

Revisions

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