for(key in obj) vs for with Object.keys

Edit on GitHub

Setup

var obj = {};
var count = 10;
do {
    obj["key" + count + ""] = "val" + count + "";
} while(count--);

Tests

  • for(key in obj)

    var temp = [];
    for(var key in obj) {
       temp.push(obj[key]);
    }
  • for with Object.keys

    var temp = [];
    var keys = Object.keys(obj);
    for(var i = 0, len = keys.length; i < len; i++) {
       temp.push(obj[keys[i]]);
    }