如何从对象数组获取ID并制作数组

时间:2019-03-11 17:12:26

标签: javascript arrays

var arrayOfObj = [{id: 41, uid: "62d0e9d5-25d4"},
        {id: 42, uid: "62d0e9d5-25d4},
        {id: 43, uid: "62d0e9d5-25d4},
        {id: 44, uid: "62d0e9d5-25d4}];

预期结果:a = [41,42,43];

2 个答案:

答案 0 :(得分:1)

Array#map一起使用

arrayOfObj.map(a=>a.id)

答案 1 :(得分:0)

您可以使用javascript映射功能来实现。 在此处阅读文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map