Test name | Executions per second |
---|---|
Array.prototype.concat | 3516330.0 Ops/sec |
spread operator | 5356973.0 Ops/sec |
copy on push | 1417783.4 Ops/sec |
directly push | 3190372.0 Ops/sec |
flat | 1.6 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 ]);