5

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;
JangoCG
  • 823
  • 10
  • 23
  • There's no `res` or `data` in your code. – palaѕн Feb 28 '20 at 13:38
  • It's one of the examples on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Unpacking_fields_from_objects_passed_as_function_parameter – Andreas Feb 28 '20 at 13:38
  • 1
    if you want only get objectId then use this `const objectId = res.data.d.results.ObjectID` – raq Feb 28 '20 at 13:38

1 Answers1

5

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)
Maheer Ali
  • 35,834
  • 5
  • 42
  • 73