例如 a = [{id:1,age:10},{id:2,age:20},{id:3,age:30}] 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:'男'}]
2 回答
qq_笑_17
TA贡献1818条经验 获得超7个赞
<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>
添加回答
举报
0/150
提交
取消