Categories
JavaScript Answers

How to copy array items into another array with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *