Test name | Executions per second |
---|---|
Array.prototype.concat | 2095507.6 Ops/sec |
spread operator | 2888256.8 Ops/sec |
copy on push | 1387847.4 Ops/sec |
directly push | 1687021.2 Ops/sec |
flat | 0.9 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 ]);