Array.prototype.forEach VS for...of

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 arr2 = [];
arr1.forEach((item) => {
	arr2.push(item);
});
ready
for...of
const arr2 = [];
for (const item of arr1) {
	arr2.push(item);
}
ready

Revisions

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