The spread operator can also be used to make array values a part of another array. The following example code that demonstrates how to make the values of an existing array a part of another array while creating it:
let array1 = [2,3,4];let array2 = [1, ...array1, 5, 6, 7];console.log(array2); //Output "1, 2, 3, 4, 5, 6, 7"
Consider the following code:
let array2 = [1, ...array1, 5, 6, 7];
This previous code is equivalent to:
let array2 = [1, 2, 3, 4, 5, 6, 7];