forEach vs map when iterating through array

Benchmark created on


Description

Which is quicker when iterating through an array? Is it forEach of .map?

Test runner

Ready to run.

Testing in
TestOps/sec
forEach method
const arr = [1, 2, 3, 4, 5, 6, "some string", false, "another string"];
let outputArr = [];

arr.forEach((x) => {
	outputArr.push(x);
});

console.log(outputArr);
ready
map method
const arr = [1, 2, 3, 4, 5, 6, "some string", false, "another string"];

let outputArr = arr.map((x) => {
	return x;
});

console.log(outputArr);
ready

Revisions

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