{"result":[{"id":1,"currency":"USD"},{"id":2,"currency":"PLN"},{"id":3,"currency":"EUR"}],"success":true}
我想拥有一个只有id的数组:
[1, 2, 3]
答案 0 :(得分:0)
let data = {result":[{"id":1,"currency":"USD"},{"id":2,"currency":"PLN"},{"id":3,"currency":"EUR"}],"success":true};
let ids = data.result.map(item => item.id);
在这里有效
答案 1 :(得分:0)
您可以使用array#map
var arr = {"result":[{"id":1,"currency":"USD"},{"id":2,"currency":"PLN"},{"id":3,"currency":"EUR"}],"success":true};
console.log(arr['result'].map(a=>a.id))