How to destructure nested object

Viewed 1898

This is the response.data I get from my post request. I only want to have the ObjectID out of this response

 {
     d: {
        results: {
          __metadata: [Object],
          ObjectID: '00163E6CDDFC1EEA96C57123A5C6DDE5',
          InformationLifeCycleStatusCode: 'AC',
          ID: '9000001424'
        }
      }
    }

This is what I got so far but i need to somehow get into the results object

        const{"ObjectID: objectID} = res.data;
1 Answers

You need to give complete path when you have to destrcuture a nested property.

const obj =  {
     d: {
        results: {
          __metadata: [Object],
          ObjectID: '00163E6CDDFC1EEA96C57123A5C6DDE5',
          InformationLifeCycleStatusCode: 'AC',
          ID: '9000001424'
        }
      }
    }

const {d : {results : {ObjectID}}} = obj;

console.log(ObjectID)

Related