js 两个数组数据处理大佬们有什么好的建议?

第一个数组:
(6)[{…},{…},{…},{…},{…},{…}__ob__:Observer]
0:
dataContent:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA"
topic:"名称"
1:
dataContent:(...)
topic:(...)
第二个数组:
(6)[Array(2),Array(3),Array(4),Array(3),Array(1),Array(1)]
0:Array(2)
0:{content:"户籍一",grand:0,percent:0,resultCount:0,validPercent:0}
1:{content:"户籍二",grand:0,percent:0,resultCount:0,validPercent:0}
length:2
1:Array(3)
0:{content:"人均500元",grand:0,percent:0,resultCount:0,validPercent:0}
1:{content:"人均300元",grand:0,percent:0,resultCount:0,validPercent:0}
2:{content:"人均400元",grand:0,percent:0,resultCount:0,validPercent:0}
length:3
2:(4)[{…},{…},{…},{…}]
.....
求两个数组的数据合并(归并)
想要得到结果:
[
{
"dataContent":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA",
"exportContent":[
{
"content":"户籍一",
"grand":"0",
"percent":"0",
"resultCount":0,
"validPercent":"0"
}
],
"topic":"名称"
}
]
千万里不及你
浏览 255回答 2
2回答

哔哔one

vardata1=[{dataContent:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA",topic:"名称"},{dataContent:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA",topic:"名称"},{dataContent:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA",topic:"名称"}]vardata2=[[{content:"户籍一",grand:0,percent:0,resultCount:0,validPercent:0},{content:"户籍二",grand:0,percent:0,resultCount:0,validPercent:0}],[{content:"户籍一",grand:0,percent:0,resultCount:0,validPercent:0},{content:"户籍二",grand:0,percent:0,resultCount:0,validPercent:0},{content:"户籍二",grand:0,percent:0,resultCount:0,validPercent:0}],[{content:"户籍一",grand:0,percent:0,resultCount:0,validPercent:0},{content:"户籍二",grand:0,percent:0,resultCount:0,validPercent:0}],]functionmergeData(data1,data2){returndata1.map((item,index)=>({...item,exportContent:data2[index]}))}console.log(mergeData(data1,data2))

一只斗牛犬

vararr1=[{dataContent:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA1",topic:"名称1"},{dataContent:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArIA2",topic:"名称2"}];vararr2=[[{content:"户籍一",grand:0,percent:0,resultCount:0,validPercent:0},{content:"户籍二",grand:0,percent:0,resultCount:0,validPercent:0}],[{content:"人均500元",grand:0,percent:0,resultCount:0,validPercent:0},{content:"人均300元",grand:0,percent:0,resultCount:0,validPercent:0},{content:"人均400元",grand:0,percent:0,resultCount:0,validPercent:0}]];varnewArr=[];for(leti=0;i
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript