b = [{id:3,sex:'男'},{id:1,sex:'男'},{id:2,sex:'女'}]
合并后
c = [{id:1,age:10,sex:'男'},{id:2,age:20,sex:'女'},{id:3,age:30,sex:'男'}]
翻阅古今
浏览 1545回答 2
2回答
qq_笑_17
<script> const a = [{id:1,age:10},{id:2,age:20},{id:3,age:30}]; const b = [{id:3,sex:'男'},{id:1,sex:'男'},{id:2,sex:'女'}]; let c = []; for(let u of a) { const temp = b.filter(i => i.id === u.id)[0]; c.push({...u, ...temp}); } console.log(c);</script>