To copy array items into another array with JavaScript, we use the concat
function.
For instance, we write
const arrayA = [1, 2];
const arrayB = [3, 4];
const newArray = arrayA.concat(arrayB);
to call arrayA.concat
with arrayB
to return a new array with arrayA
‘s contents with arrayB
‘s contents being it.