Clone and change

Benchmark created on


Setup

const arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];

Test runner

Ready to run.

Testing in
TestOps/sec
Array from
const newArr = Array.from(arr);
newArr[2] = 2;
newArr[3] = 3;
newArr[4] = 4;
ready
spread
const newArr = [...arr];
newArr[2] = 2;
newArr[3] = 3;
newArr[4] = 4;
ready
old school
const l = arr.length;
const newArr = new Array(l);

for (let i = 0; i < l; i++) {
	newArr[i] = arr[i];
}

newArr[2] = 2;
newArr[3] = 3;
newArr[4] = 4;
ready
Arr with
const newArr = arr.with(2, 2).with(3, 3).with(4, 4);
ready

Revisions

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