ES6 deep nested object destructuring

前端 未结 1 726
孤独总比滥情好
孤独总比滥情好 2020-12-14 15:04

I have an object called this.props which contains

{
 actions: Object,
 dirty: false,
 form: \"Statement\",
 autofill: functon(),
 **statement: O         


        
相关标签:
1条回答
  • 2020-12-14 15:24

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

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

    That way you get both isConfirmed and the whole statement object.

    References:

    • https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Nested_object_and_array_destructuring
    0 讨论(0)
提交回复
热议问题