0

A few minutes ago, i met with this:

var array = [1, 2, 4, 6];
var [two, four, eight, twelve] = array.map(num => num * 2);
console.log(four) // 4

Can someone explain how this works?

  • 1
    `map()` returns an array. The assignment to an array like this is called a [destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) – Mark Apr 30 '18 at 14:56
  • 1
    take alook at [Destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) – Taki Apr 30 '18 at 14:56
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment – Kevin Boucher Apr 30 '18 at 14:57
  • Also, check out [What does this symbol mean in JavaScript?](https://stackoverflow.com/q/9549780/4642212). – Sebastian Simon Apr 30 '18 at 15:07

0 Answers0