You can use push
and apply
function to append two arrays.
var array1 = [11, 32, 75];
var array2 = [99, 67, 34];
Array.prototype.push.apply(array1, array2);
console.log(array1);
It will append array2
to array1
. Now array1
contains [11, 32, 75, 99, 67, 34]
.
This code is much simpler than writing for
loops to copy each and every items in the array.