我正在获取对象数组,我想从该数组中获取ID和名称,但不应使用foreach或任何其他循环来完成。这是我的数组
[{ companyId : "5cc6ca1b280cdf1522d1a3a4",
email : "abc+103@gmail.com",
firstName : "test",
inviteAccepted : false,
lastName : "test",
_id : "5d512444955d441dfc52f640"
}, {
companyId : "5cc6ca1b280cdf1522d1a3a4",
email : "abc+104@gmail.com",
firstName : "test",
inviteAccepted : false,
lastName : "test",
_id : "5d528778e741722391d1fdd3"
}]
我尝试过
var IdArray = users.map(function (el:any) {
return {
_id:el._id,
sourceName:el.firstName+el.lastName
};
});
但是它将sourceName显示为undefined 我希望我的结果像这样
[{ sourceName : "test test",
_id : "5d512444955d441dfc52f640"
}, {
sourceName : "test test",
_id : "5d528778e741722391d1fdd3"
}]