var a = [100,200,300]; var b = [{id:'100',name:'小红'},{id:'300',name:'小明'},{id:'200',name:'小蓝'}]; var result = b.sort((aa, bb) => (a.indexOf(aa.id - 0) - a.indexOf(bb.id - 0))); // 不考虑重复ID的话方法还有很多: result = a.map(el_a=>(b.find(el_b => el_b.id == el_a))); result = b.reduce((acc,cur) => (acc[a.indexOf(cur.id - 0)] = cur, acc), []);
2.1m questions
2.1m answers
60 comments
57.0k users