1.元数据constarr1=["#355b54","#12d806","#748aac"];constarr2=[{type:"一类"},{type:"二类"},{type:"三类"},{type:"四类"},{type:"五类"},{type:"六类"},{type:"七类"},{type:"其他"}];2.需要将arr中数据按照索引插入到arr2,arr1商量继续从arr[0]添加.3.最后的效果是这样:constarr=[{type:"一类",color:"#355b54"},{type:"二类",color:"#12d806"},{type:"三类",color:"#748aac"},{type:"四类",color:"#355b54"},{type:"五类",color:"#12d806"},{type:"六类",color:"#748aac"},{type:"七类",color:"#355b54"},{type:"其他",color:"#12d806"}]
2 回答

阿晨1998
TA贡献2037条经验 获得超6个赞
constarr=arr2.map((item,index)=>({...item,color:arr1[index%arr1.length]}))

慕田峪9158850
TA贡献1794条经验 获得超7个赞
letarr1Length=arr1.lengthletresult=arr2.map((item,index)=>{letidx=index%arr1Length//取余,首尾循环return{...item,color:arr1[idx]}})console.log(result)
添加回答
举报
0/150
提交
取消