+ 1
I don't understand this for-of loop. How I get this result. Is this some kind of destructuring in for-of?
arr=[] for(let {x=3,y=2} of [{x:1},{y:4}]){ arr.push(x,y) } arr.forEach(k=>console.log(k)) // 1 2 3 4
2 Respostas
+ 1
Yes you are correct, it is destructuring combined with defaulting.
The code loops through a list of two objects, and extracts two variables x and y. But the first object contains only x, so y is defaulted to 2. The second object contains only y, so x is defaulted to 3. And in each iteration the two values are added to the array.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
+ 1
Thanks for simple answer :)