vue通过一组id匹配另一个数组中的对象

let list1=[1,2,3,4]
let list2=[
{id:1,name:'aaa'},
{id:2,name:'bbb'},
{id:3,name:'ccc'},
{id:4,name:'ddd'},
{id:5,name:'eee'},
]
let list=[]
list=list1.map(item=>list2.find(i=>i.id==item)[0])
console.log(list)
// [
{id:1,name:'aaa'},
{id:2,name:'bbb'},
{id:3,name:'ccc'},
{id:4,name:'ddd'},
]

你可能感兴趣的:(vue.js,javascript,前端)