forEach vs map when iterating through a simple array (v2)

Revision 2 of this benchmark created on


Description

Which is quicker when iterating through a simple array? Is it forEach or 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.