javascript - 如何从数组中提取特定值并将这些值分配给变量以在下一个邮递员请求中使用它
问题描述
在为邮递员编写 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;```
推荐阅读
- python - 由于传递给 __init__() 的附加参数,django 中的嵌套视图给出了 TypeError
- java - 方法不会从其超类覆盖
- wordpress - 如何通过以下方式将 Wordpress 与 Ultimate Member 和 Media Library 文件夹结合使用
- javascript - promise catch 不解析 json
- angularjs - AngularJS模拟ngChange用于单元测试中的选择
- c - 微ECC值可能吗?
- mysql - 如何通过多个表插入数据
- r - 使用多个回归器预测每周时间序列数据
- r - R中函数内的子集疑难解答
- ruby-on-rails - Rspec 规格控制器