0

I have an API that returns a response. The response contains a "data" field that I can access with response.data. It looks like this:

{
  statusCode: 201,
  timestamp: '2021-06-26T12:39:40-07:00',
  timestampMs: 1624736380095,
  shortMessage: 'Created',
  longMessage: 'Created',
  errors: [],
  customs: [ { key: 'contactId', value: '379332970' } ]
}

response.data.customs looks like this:

[ { key: 'contactId', value: '1193400871' } ]

I need to access only the value of contactId in the customs field. I tried response.data.customs.contactId, response.data.customs.[contactId] etc. and nothing works. I'm sure I'm missing something simple here. Can anyone help?

EDIT: Without needing to complicate things, the simplest solution is: response.data.customs[0].value

Jimmy D
  • 5,183
  • 15
  • 49
  • 67
  • 1
    contactId is not a key. It is a value inside an array element in customs. Do you want to use get the corresponding `value` key for that array element? – Tushar Shahi Jun 26 '21 at 19:50

0 Answers0