What could be the reason for this... This is how destructuring assignment and aggregation operations are stipulated...
In the rvalue array of the assignment operation, there are no elements in the third position and beyond, then the carray is of course an empty array...
let [x,y, ...c] = ['a']
等于
let x, y, c = ..c
['a'].forEach(function (item, index, array) {
if (index === 1) {
x = array[index]
}
if (index === 2) {
y = array[index]
}
if (index === 3) {
c = array[index]
}
})
// 因为只有一个值,所以就x的变化了,而y和c没有变
// 循环里面是瞎扯的,但大概是这个原理
First of all, in ES6,
...
itself has the function of a structural object.So for destructuring assignment and the one-to-one correspondence between elements, the question is broken down into
What could be the reason for this...
This is how destructuring assignment and aggregation operations are stipulated...
In the rvalue array of the assignment operation, there are no elements in the third position and beyond, then the
c
array is of course an empty array...Array destructuring has different rules for default parameters and variable parameters