Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array concat vs spread operator vs push vs splice vs for-each push vs for-of push
(version: 0)
Compare different techniques for combining 2 arrays into either a new array or the source array
Comparing performance of:
Array.prototype.concat vs spread operator vs Push vs Splice vs Push for-each vs Push for-of
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ "hello", true, 7 ]; var a = [ 1, 2 ]; var b = a.concat(params);
spread operator
var params = [ "hello", true, 7 ] var a = [ 1, 2 ]; var b = [ ...a, ...params ];
Push
var params = [ "hello", true, 7 ]; var a = [ 1, 2 ]; var b = a.push(...params);
Splice
var params = [ "hello", true, 7 ]; var a = [ 1, 2 ]; var b = a.splice(params.length, 0, ...params);
Push for-each
var params = [ "hello", true, 7 ]; var a = [ 1, 2 ]; params.forEach(v => a.push(v));
Push for-of
var params = [ "hello", true, 7 ]; var a = [ 1, 2 ]; for(v of params) a.push(v);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
Push
Splice
Push for-each
Push for-of
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:
Splice+Spread vs concat to concat arrays
unshift vs spread vs concat
Large Array: concat vs spread vs push
Array.prototype.concat vs spread operator vs push with spread
Array concat vs spread operator vs push with short arrays
Comments
Confirm delete:
Do you really want to delete benchmark?