Array.prototype.forEach VS for

Benchmark created on


Setup

const arr1 = new Array(10000).fill(0).map((_, index) => index);

Test runner

Ready to run.

Testing in
TestOps/sec
Array.prototype.forEach
const obj1 = {};
arr1.forEach((item, index) => {
	obj1[index] = item;
});
ready
for
const obj1 = {};
for (let index = 0; index < arr1.length; index++) {
	const item = arr1[index];
	obj1[index] = item;
}
ready

Revisions

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