Iterate over all properties in an object

Benchmark created on


Setup

const obj = { a: 1, b: 2, c: 3, d: 4 }

Test runner

Ready to run.

Testing in
TestOps/sec
for...in
for (const prop in obj) { obj[prop]++ }
ready
Object.entries() + forEach()
Object.entries(obj).forEach(item => obj[item[0]]++)
ready
Object.entries() + for...of
for (const [prop, val] of Object.entries(obj)) {
  obj[prop]++
}
ready
Object.keys() + forEach()
Object.keys(obj).forEach(prop => obj[prop]++)
ready
Object.keys() + for...of
for (const prop of Object.keys(obj)) {
  obj[prop]++
}
ready

Revisions

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