letary=[{fileName:"文档1",nodeId:"1133275924701949952",},{fileName:"文档2",nodeId:"1133275743956807681",},{fileName:"文档3",nodeId:"1133275683449434112",},{fileName:"文档4",nodeId:"1133275743956807681",},{fileName:"文档5",nodeId:"1133275683449434112",},{fileName:"文档6",nodeId:"1133275924701949952",}]//将相同id的文件名以“,”拼接起来,放在数组中的一项得到=>["文档1,文档6","文档2,文档4","文档3,文档5"],怎么写啊大佬们
2 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
functiontransformData(ary){consttempObj=ary.reduce((prev,current)=>{prev[current.nodeId]=prev[current.nodeId]||[];prev[current.nodeId].push(current.fileName);returnprev;},{});constresult=[];for(letnodeIdintempObj){constfileName=tempObj[nodeId];result.push(fileName.join(','));}returnresult;}
添加回答
举报
0/150
提交
取消