gpt4 book ai didi

javascript - ES6 深度嵌套对象解构

转载 作者:IT王子 更新时间:2023-10-29 03:20:13 26 4
gpt4 key购买 nike

我有一个名为 this.props 的对象,其中包含

{
actions: Object,
dirty: false,
form: "Statement",
autofill: function(),
**statement: Object**
}

语句包含

{
firstName: "John"
lastName: "Peter"
isConfirmed: true
}

我想使用 es6 解构在同一行中提取 statement 对象和 isConfirmed 属性

我试过了

const { statement: isConfirmed, isAdmin } = this.props

当我执行 let a = isConfirmed, b = statement 时出现错误

最佳答案

I would like to extract statement object and the isConfirmed property in the same line

const { statement: { isConfirmed }, statement } = this.props;

这样你就可以得到 isConfirmed 和整个 statement 对象。

引用资料:

关于javascript - ES6 深度嵌套对象解构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40622385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com