js多个数组(3个以上)如何合并成json形式

题目描述
arr1=[1,2,3,4,5];arr2=[a1,a2,a3,a4,a5];arr3=[b1,b2,b3,b4,b5];arr4=[c1,c2,c3,c4,c5];arr5=[11,22,33,44,55];多个数组类似这个形式,数组里内容是不定的需要合并成这个形式[{"a":"1","b":"a1","c":"b1","d":"c1","e":"11"},{"a":"2","b":"a2","c":"b2","d":"c2","e":"22"},{"a":"3","b":"a3","c":"b3","d":"c3","e":"33"},{"a":"4","b":"a4","c":"b4","d":"c4","e":"44"},{"a":"5","b":"a5","c":"b5","d":"c5","e":"55"}]
两个数组我用的2个for循环嵌套和if语句判断push到对象里如果更多(5-6个数组)有什么更好的办法。
红糖糍粑
浏览 3534回答 3
3回答

weixin_慕仰3408494

大佬 你这问题解决了吗  我也遇到这问题了

梦里花落0921

动态传入数组,动态计算key,即可,代码如下:constarr1=[1,2,3,4,5];constarr2=['a1','a2','a3','a4','a5'];constarr3=['b1','b2','b3','b4','b5'];constarr4=['c1','c2','c3','c4','c5'];constarr5=[11,22,33,44,55];functionparse(...arrList){constresult=[]for(leti=0,l=arrList.length,arr,key;i

汪汪一只猫

看错问题,再修改一下:import_from'lodash'constarr1=[1,2,3,4,5];constarr2=['a1','a2','a3','a4','a5'];constarr3=['b1','b2','b3','b4','b5'];constarr4=['c1','c2','c3','c4','c5'];constarr5=[11,22,33,44,55];constresult=_.zip(arr1,arr2,arr3,arr4,arr5)console.log(result)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript