I have a reference to an array a1
. I have an array of extra values a2
. I want to concatenate all the values of a2
onto a1
, mutating the original array.
Using concat()
does not work, because it is non-mutating. For example:
var a0 = [1,2,3];
var a1 = a0;
var a2 = [4,5,6];
a1 = a1.concat(a2);
console.log(a1); // [1,2,3,4,5,6] YAY
console.log(a0); // [1,2,3] BOO
Is there a better way to do this other than something like:
for (var i=0; i<a2.length; ++i) a1.push(a2[i]);