Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Chrome 92
Mac OS X 10.15.7
Desktop
3 years ago
Test name Executions per second
Array.prototype.concat 3982290.5 Ops/sec
spread operator 6570574.0 Ops/sec
copy on push 1598194.8 Ops/sec
directly push 4045957.5 Ops/sec
flat 1.4 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 ]);