How can you concatenate multiple arrays using JavaScript operators?

In JavaScript, you can concatenate multiple arrays using the array spread (`...`) operator or the `concat()` method. Both approaches provide a way to create a new array that combines the elements of multiple arrays.

Using the Array Spread Operator (`...`):

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

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

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


In this example, the array spread operator `...` is used to create a new array `combinedArray` by combining the elements of `array1`, `array2`, and `array3`.

Using the `concat()` Method:


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

let combinedArray = array1.concat(array2, array3);

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


In this example, the `concat()` method is used to create a new array `combinedArray` by concatenating the elements of `array1`, `array2`, and `array3`.

Both approaches result in the same concatenated array. Choose the method that you find more readable or that better fits your coding style. The array spread operator is a more concise and modern syntax, while the `concat()` method is a traditional approach.