How to use the JavaScript spread operator to concatenate multiple arrays?

Estimated read time 1 min read

The JavaScript spread operator ... allows you to concatenate multiple arrays into a single array.

Here’s an example of using the spread operator to concatenate multiple arrays:

let array1 = [1, 2, 3];
let array2 = [4, 5, 6];
let array3 = [7, 8, 9];

let concatenatedArray = [...array1, ...array2, ...array3];

console.log(concatenatedArray); // Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

In the example, the spread operator is used to spread the elements of each array into a new array. The result is a single array that contains all the elements of the original arrays, concatenated together.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply