Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In JavaScript, the method of merging one array into another array is by using the concat() method. This method combines two or more arrays into one new array without changing the original arrays.

Syntax:

newArray = arr1.concat(arr2);

where arr1 is the original array and arr2 is the array that is going to be merged into arr1.

Example:

let arr1 = [1, 2, 3]; let arr2 = [4, 5, 6];

let newArray = arr1.concat(arr2);

console.log(newArray); // Output: [1, 2, 3, 4, 5, 6]