仅具有特定字段的数组解构+扩展语法?

Array Destructuring + spread syntax with specific field only?

let arr = [{name: 'john', age:17}, {name: 'Doe', age: 21}];

//let dropDownHumanOptions = ['All', ...arr.name, 'Cancel']
//let dropDownHumanOptions = ['All', ...{arr.name}, 'Cancel']

//Expected: let dropDownHumanOptions = ['All', 'john', 'Doe', 'Cancel']

我想知道是否有任何类似的语法,我们可以只提取其中一个字段并使用扩展语法在另一个数组的中间组合?

您需要传播映射的名称。

var array = [{name: 'john', age:17}, {name: 'Doe', age: 21}],
    dropDownHumanOptions = ['All', ...array.map(({ name }) => name), 'Cancel'];

console.log(dropDownHumanOptions);