Object Iteration

Benchmark published by System on

Description

Compare ways to iterate over object properties.

Setup

const obj = {};
for(let i=0; i<1000; i++) obj['key'+i] = i;

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Object.keys()
let sum = 0;
const keys = Object.keys(obj);
for(let i=0; i<keys.length; i++) sum += obj[keys[i]];
ready
Object.entries()
let sum = 0;
const entries = Object.entries(obj);
for(let i=0; i<entries.length; i++) sum += entries[i][1];
ready
for...in loop
let sum = 0;
for(const key in obj) {
  if (obj.hasOwnProperty(key)) sum += obj[key];
}
ready

Revisions

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

Revision 1
publishedby Systemon