Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36
Chrome 88
Mac OS X 11.2.0
Desktop
4 years ago
Test name Executions per second
Array.prototype.concat 3116563.5 Ops/sec
spread operator 5022208.0 Ops/sec
copy on push 1255670.0 Ops/sec
directly push 3129265.2 Ops/sec
flat 1.0 Ops/sec
HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var existing = [ 1, 2, "hello", true, 7 ];
var newi = [1, 1, 1];
Tests:
  • Array.prototype.concat

     
    var other = existing.concat(newi);
  • spread operator

     
    var other = [ ...existing, ...newi ];
  • copy on push

     
    var other = newi.forEach(i => existing.concat().push(i));
  • directly push

     
    newi.forEach(i => existing.push(i));
  • flat

     
    var other = _.flatten([ existing, newi ]);