Test name | Executions per second |
---|---|
for-in | 0.9 Ops/sec |
Object.keys | 1.0 Ops/sec |
var obj = {
'a': 1,
'b': 1,
'c': 1,
'd': 1,
'e': 1,
'f': 1,
'g': 1
};
for (var i=10000; i > 0; i--) {
for (var key in obj) {
console.log(key);
}
}
for (var i=10000; i > 0; i--) {
const keys = Object.keys(obj);
for (const key of keys) {
console.log(key);
}
}