Iteration over all object values

Benchmark created on


Description

Given an object "obj" with lots of properties, compare different solutions to iterate over each value to operate on them.

Setup

const obj = {};
for (let i = 0; i < 10000; ++i) {
	obj['property-' + i] = i;
}
function operate(x) {
	if (x % 2) {
		return ++x;
	}
	return --x;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Using Object.values().forEach()
Object.values(obj).forEach(o => operate(o))
ready
Using for...in
for (let o in obj) {
	operate(o)
}
ready

Revisions

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