vardata=[{name:'color',key:[1,2,3,4,5]},{name:'size',key:[1,2,3,4,5]},{name:'other',key:[1,2,3,4,5]},{name:'type',key:[1,2,3,4,5]},];vararr=[{color:"pink",size:"xm",other:'aaa',type:'one',price:100,weight:456},{color:"red",size:"xm",other:'bbb',type:'two',price:789,weight:789}];有两个数组data和arr,在data数组中的子对象的排列顺序为,第一个:{name:'color',key:[1,2,3,4,5]},第二个:{name:'size',key:[1,2,3,4,5]},第三个:{name:'other',key:[1,2,3,4,5]},第四个:{name:'type',key:[1,2,3,4,5]}。在arr数组中,子对象中color:"pink"和color:"red",属性,因为在data中,属性name:"color",排在data数组中的第一个,所以arr数组中两个子对象的color:"pink"color:"red",要转换成option1:"pink"和option1:"red",同样道理,需要把arr数组,变成下面arr1的数据格式,请问有什么比较灵活的方法可以实现?vararr1=[{option1:"pink",option2:"xm",option3:"aaa",option4:"one",price:100,weight:456},{option1:"red",option2:"xm",option3:"bbb",option4:"two",price:789,weight:789}]
相关分类