How to Copy Data from Two Arrays into a Third Array in JavaScript?

Estimated read time 1 min read

You can copy data from two arrays into a third array in JavaScript by concatenating the arrays and creating a new array. Here’s an example:

let array1 = [1, 2, 3];
let array2 = [4, 5, 6];

let combinedArray = array1.concat(array2);

console.log(combinedArray);

In this code, we first define two arrays, array1 and array2.

Next, we use the concat() method to combine the two arrays into a single array, which we store in the combinedArray variable.

Finally, we log the value of the combinedArray to the console.

This will output the following:

[1, 2, 3, 4, 5, 6]

Note that this creates a new array that contains the elements of both array1 and array2, and does not modify either of the original arrays.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply