Array shallow clone techniques

Benchmark created on


Setup

var arr = [];
for (i = 0; i < 1000; i++) {
  arr[i] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
slice
arr.slice();
ready
concat 1
arr.concat([]);
ready
concat 2
[].concat(arr)
ready
while loop
var length = arr.length;
var clone = Array(length);
var i = -1;
while (++i < length) {
  clone[i] = arr[i];
}
ready
Spread
[...arr]
ready

Revisions

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