Ask Your Question
4

What is the method of merging one array into another array in Javascript?

asked 2021-08-25 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-11-30 18:00:00 +0000

qstack gravatar image

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]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-25 11:00:00 +0000

Seen: 8 times

Last updated: Nov 30 '21