I have a way of thinking which makes it very easy to understand and remember how '...' works.
var arr = [1,2,3] // this is arr which is the array
on the other hand
...arr // this is whatever inside arr, which is 1,2,3
So you can also think of it as taking what is inside of an array.
Note that by its own, ...arr is not a valid syntax. You can use it in
many ways , two of them coming to my mind are :
1 - Pass what is inside an array to a function
var arr = [ 1,2,3 ]
var myFunc = function(a,b,c) {
console.log(a,b,c)
}
myFunc(..arr) // logs 1 2 3
myFunc(1,2,3) // logs 1 2 3
2 - Take what is inside of an array and use them in another array.
var arr = [ 1,2,3 ]
var foo = [ ...arr, 4,5,6 ] // now foo is [ 1,2,3,4,5,6 ]