let selectIds = [1, 3] // 选中id数组
let allData = [
{ id: 1, name: '123' },
{ id: 2, name: '234' },
{ id: 3, name: '345' },
{ id: 4, name: '456' },
] // 源数据
let newList = [] // 最终数据
selectIds.map((i) => {
allData.filter((item) => {
item.id == i && newList.push(item)
})
})
console.log("🚀 ~ handlerAdd ~ newList:", newList)
结果:
若是根据后端id数组转换name展示只需在newList.push(item.name)