![](/img/trans.png)
[英]Access specific value base on API response, and use it for next request - Postman
[英]How do I extract specific value from an array and assigned those value to a variable to use it in next postman request
在为邮递员编写 JavaScript 时,我有点新。 我只想提取动态的id
号,每次向服务器发送请求时都会发生变化。 所以我想提取它们并将它们分配给我想在下一个邮递员删除请求中使用的变量。 不知道它是如何做到的,任何帮助将不胜感激。
[{
"id": 2286288,
"tradeIt": true,
"productId": 2066275,
"accountId": 2805,
}, {
"id": 2286290,
"tradeIt": true,
"productId": 2066275,
"accountId": 2804,
}, {
"id": 2286289,
"tradeIt": true,
"productId": 2066275,
"accountId": 2806,
}, {
"id": 2286291,
"tradeIt": true,
"productId": 2066275,
"accountId": 2808,
"assetId": 0,
}]
如果这是一个数组,你应该用你想要的对象的索引调用数组本身
//let's say
arr = [[{ "id": 2286288, "tradeIt": true, "productId": 2066275, "accountId": 2805,
}, {
"id": 2286290,
"tradeIt": true,
"productId": 2066275,
"accountId": 2804,
}, {
"id": 2286289,
"tradeIt": true,
"productId": 2066275,
"accountId": 2806,
}, {
"id": 2286291,
"tradeIt": true,
"productId": 2066275,
"accountId": 2808,
"assetId": 0,
}
]
//to return for example id 2286291
let index =3;
arr[index].id;```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.