Yes, you can merge multiple arrays into one array using the concat()
method, or the spread operator ...
.
concat()
The concat()
method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = arr1.concat(arr2);
console.log(arr3); // [1, 2, 3, 4, 5, 6]
Spread operator
The spread operator ...
is used to expand an iterable object into the list of arguments.
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = [...arr1, ...arr2];
console.log(arr3); // [1, 2, 3, 4, 5, 6]