Search code examples
response

Axios - how to get value from nth object


I have a response like below:

response = 
[
 {
   "location":{
       some data
   },
   "library":[
      {
          "id": 1234,
          "name": "CCT"
      },
      {
          "id": 3546,
          "name": "KAT"
      },
      {
          "id": 6577,
         "name": "LLC"
      },
   ]
  }
]

No I would like to get value id=3546.

When I do something like

response.data[0].library[0].id then I get id=1234

but how to retrieve value from the second or third object, please?

I tried:

response.data[0].library[0].id(1)

or

response.data[0].library[0].id.get(1)

but it's not a right solution :(


Solution

  • Here ya go: :)

    response.data[0].library[1].id
    
    response.data[0].library[0] -> first element in the library object
    response.data[0].library[1] -> second element in the library object
    response.data[0].library[2] -> third element in the library object