Pushing a large array of objects into another

Benchmark created on


Setup

const list1 = [];
const list2 = [];
for (let i = 0; i < 3000; ++i) {
	list1.push({index: i, flavor: "Peach"});
	list2.push({index: i * 2, flavor: "Banana"});
}

Test runner

Ready to run.

Testing in
TestOps/sec
Spread operator
list1.push(...list2);
ready
Foreach
list2.forEach((e) => list1.push(e));
ready
For loop
for (let e of list2) {
	list1.push(e);
}
ready

Revisions

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