The destructurization?

Tell me which algorithm occurs gestructureerde assignment.

1.
var {a,aa, aaa...} = [2, 4, 23];

console.log(a, aa, aaa);

undefined undefined {0: 2, 1: 4, 2: 23}


2.

var [a,aa,..., aaa] = {a:2 aa: 4 aaa: 23};

console.log(a, aa, aaa);

undefined undefined {0: 2, 1: 4, 2: 23}

VM176:1 Uncaught TypeError: {(intermediate value)(intermediate value)(intermediate value)} is not iterable
 at <anonymous>:1:21</anonymous>


Explain how the algorithm assignment.
Of course I have read about deconstruction here and here and here.
June 10th 19 at 14:38
2 answers
June 10th 19 at 14:40
var [] = value for arrays
var {} = value for objects

... takes all the non-remitted the balance in a specified variable (spread)

The correct code your options are:
var [a,aa, aaa...] = [2, 4, 23];
console.log(a, aa, aaa);

var {a,aa, aaa...} = {a:2 aa: 4 aaa: 23};
console.log(a, aa, aaa);
Read the bottom part of the question. - icie35 commented on June 10th 19 at 14:43
Clear probably do not fully understand the question, but if I understood what the essence of this, the first is because in js all objects. But an array is just a special type.
Key a = no undefined no key aa = undefined, everything else is aaa.

The second fails because set brackets [] and the sample is not the key, and in order, the value is not searched. - Wava_Berni commented on June 10th 19 at 14:46
,
var obj = {1: 2, 2: 4, 3: 23}

var [a,aa,..., aaa] = obj;
Uncaught TypeError: obj is not iterable
 at <anonymous>:3:21</anonymous>


I imitated the array, but still not working. Maybe there is documentation, and that word is difficult to read. - icie35 commented on June 10th 19 at 14:49
The specification of such brackets determine the interpretation of the values for objects and arrays of different interpretation, in the case of arrays is called an iterator (enumeration), in the case of objects work sheet the hash table. Your links have the specs - Wava_Berni commented on June 10th 19 at 14:52
the hash table's key - value and it also can be iterated like an array, and the array also you can assign the key and value as object. not tell the difference. - icie35 commented on June 10th 19 at 14:55
June 10th 19 at 14:42
Babel sheds some light on this question.

I think, at the moment, the behavior in such cases depends on the interpreter. If you are interested in the behavior, which should be according to the specification ES6, open it and read it.
ATP I'll delve. on account of specifications, I don't know English. I would love to be revered. - icie35 commented on June 10th 19 at 14:45

Find more questions by tags JavaScript