Axios - 如何从第 n 个对象获取值

问题描述 投票:0回答:1

我有如下回复:

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

不,我想获得价值

id=3546
.

当我做类似的事情时

response.data[0].library[0].id
然后我得到
id=1234

但是如何从第二个或第三个对象中检索值呢?

我试过:

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

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

但这不是正确的解决方案:(

response axiom
1个回答
1
投票

来了::)

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
© www.soinside.com 2019 - 2024. All rights reserved.