Jos*_*sen -1 javascript destructuring arrow-functions
任何版本的 Javascript 是否支持箭头函数中数组的解构?例如
const items = [ [1, 2], [3, 4] ];
const sums = items.map( [a, b] => a + b );
Run Code Online (Sandbox Code Playgroud)
可以,但必须将参数括在括号中:
const items = [ [1, 2], [3, 4] ];
const sums = items.map(([a, b]) => a + b );
console.log(sums);Run Code Online (Sandbox Code Playgroud)