【问题标题】:Combine array and object destructuring [duplicate]结合数组和对象解构[重复]
【发布时间】:2019-09-25 14:01:00
【问题描述】:

如何从数组中销毁一个值?

const ?? = { text: ['some text'] };

【问题讨论】:

  • 解构的一般建议。如果您不确定如何从对象文字中解构特定值,请将解构语法 match 设置为对象文字。尽管在这种情况下,将作业改为const someText = object.text[0] 可能更容易阅读。

标签: javascript arrays object ecmascript-6


【解决方案1】:

const { text: [someText]} = { text: ['some text'] };

console.log(someText);

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2020-02-27
    • 2023-03-19
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 2020-09-05
    • 2021-03-11
    • 2020-07-26
    相关资源
    最近更新 更多