Test name | Executions per second |
---|---|
Array.prototype.concat | 4600818.5 Ops/sec |
spread operator | 4277373.0 Ops/sec |
copy on push | 1251066.9 Ops/sec |
directly push | 2345274.8 Ops/sec |
flat | 2.1 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var existing = [ 1, 2, "hello", true, 7 ];
var newi = [1, 1, 1];
var other = existing.concat(newi);
var other = [ existing, newi ];
var other = newi.forEach(i => existing.concat().push(i));
newi.forEach(i => existing.push(i));
var other = _.flatten([ existing, newi ]);