-1

Does any version of Javascript support destructuring of arrays in arrow functions? E.g.

const items = [ [1, 2], [3, 4] ];
const sums = items.map( [a, b] => a + b );
Josh Hansen
  • 917
  • 1
  • 9
  • 20

1 Answers1

3

You can, but you have to surround the parameter in parentheses:

const items = [ [1, 2], [3, 4] ];
const sums = items.map(([a, b]) => a + b );
console.log(sums);
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320