在js前端取得json数据后想些处理达到期望的效果。数据:data1=[{"id":1,"name":"a"},{"id":2,"name":"b"}];data2=[{"id":1,"sex":"man"},{"id":2,"sex":"man"},{"id":3,"sex":"woman"},{"id":4,"sex":"woman"}];期望:data3=[{"id":1,"name":"a","info":[{"id":1,"sex":"man"},{"id":2,"sex":"man"},{"id":3,"sex":"woman"},{"id":4,"sex":"woman"}],},{"id":2,"name":"b","info":[{"id":1,"sex":"man"},{"id":2,"sex":"man"},{"id":3,"sex":"woman"},{"id":4,"sex":"woman"}],}];我该怎么写,我的想法是把data1的每个数组取出来,然后往里面用push插入data2的数据,然后将data1的数组重新合并得出结果。写法如下:for(vari=0;i
2 回答
拉丁的传说
TA贡献1789条经验 获得超8个赞
data1=[{"id":1,"name":"a"},{"id":2,"name":"b"}];data2=[{"id":1,"sex":"man"},{"id":2,"sex":"man"},{"id":3,"sex":"woman"},{"id":4,"sex":"woman"}];for(vari=0;idata1[i].info=data2 }console.log(data1);
添加回答
举报
0/150
提交
取消