从数组第一个索引的对象中解构值

Ale*_*drs 2 javascript ecmascript-6 reactjs

如何替换从以下代码摘录中访问临时变量值?我尝试通过默认的 JS 代码获取所有值,但是,我想在这里使用解构

const temp = context.options[0]; // <----- here
const avoidPattern = [
    'foo', 'bar', 'abc', 'value', 'temp', 'num'
];


return [...avoidPattern, ...temp]
Run Code Online (Sandbox Code Playgroud)

Pra*_*mar 6

如果我们同时解构object和 ,这也是可能的。array

const context = { options: [1, 2, 3] };
const { options: [temp] } = context;

console.log(temp);
Run Code Online (Sandbox Code Playgroud)