If you use concat , the original array will be unmodified. If you have a link to it, you will not see new elements.
var arr1 = [ "a", "b" ]; var arr2 = [ "c", "d" ]; arr1.push.apply(arr1, arr2);
Mainly:
[ "a", "b" ].push("c", "d");
apply turns an array into a list of arguments. The first argument to apply is context , by the way, arr1 in this case, since you want push to apply to arr1 .
You can use concat :
var arr1 = [ "a", "b" ]; var arr2 = [ "c", "d" ]; var arr3 = arr1.concat(arr2);
This leaves the original arr1 as it was. You have created a new array with two elements arr1 and arr2 . If you have a link to the original arr1 , it will not be changed. This may be a reason not to want to use concat .
source share