Repopulate an array

Benchmark created on


Setup

const slug = [...Array(9000)].map((o, key) => ({key, value: `Value ${key + 1}`}))

Test runner

Ready to run.

Testing in
TestOps/sec
forEach with push
const list = [];
list.length = 0;
slug.forEach(item => list.push(item));
ready
reduce with spread
const list = [];
list.length = 0;
slug.reduce((acc, cur) => [...acc, cur], list);
ready
reduce with push
const list = [];
list.length = 0;
slug.reduce((acc, cur) => {
	acc.push(cur);
	return acc;
}, list);
ready
reduce with push, comma notation
const list = [];
list.length = 0;
slug.reduce((acc, cur) => (acc.push(cur), acc), list);
ready

Revisions

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