Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Cloning an array
(version: 0)
Cloning a small array of 40 items
Comparing performance of:
Using array slice vs Using array spread vs Using array push and spread vs Using for loop and push vs Using array concat
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = []; for (let m = 0; m < 40; m++) { array.push(m); }
Tests:
Using array slice
let clone = array.slice();
Using array spread
let clone = [...array];
Using array push and spread
let clone = []; clone.push(...array);
Using for loop and push
let clone = []; for (let i = 0; i < array.length; i++) { clone.push(array[i]); }
Using array concat
let clone = [].concat(array);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Using array slice
Using array spread
Using array push and spread
Using for loop and push
Using array concat
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Array cloning
JS Array Slice vs Array Spread
shallow copy of 6M elements array
Array cloning 2023
Comments
Confirm delete:
Do you really want to delete benchmark?