let arr1 = ["小明", "小燕子"];
let arr2 = [{
names: "小明",
id: 1
}, {
names: "小红",
id: 2
}, {
names: "小燕子",
id: 3
}];
let arr3 = [];
arr1.forEach(element => {
let ids = arr2.find(ele => {
return ele.names == element
})
arr3.push(ids.id)
});
console.log(arr3);
通过返回的数组找到原数组中对应的ID,并返回
最新推荐文章于 2023-12-28 16:46:01 发布