For in vs Object.*.forEach vs Object.values 2
Date tested:
3 months ago
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0
Test name
Executions per second
For In
2418.2 Ops/sec
Object values
12333.5 Ops/sec
Object keys for of
1434.5 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var obj = new Object() var keys = (new Array(10000)).fill(0).map((x, i) => { return i + 1 }) keys.forEach((x) => { obj['prop' + x] = x })
Tests:
For In
const arr = []; for (const key in obj) { arr.push(obj[key]); }
Object values
const arr = Object.values(obj);
Object keys for of
const arr = []; for (const key of Object.keys(obj)) { arr.push(obj[key]); }
Open this result on MeasureThat.net