原数组格式
let arr = [
[
{sellingPrice: 43535, discountPrice: 4534, freight: 12},
{sellingPrice: 4536, discountPrice: 342, freight: 3},
],
[
{stockNum: 2141, skuId: 168},
{stockNum: 345, skuId: 654}
],
[
{
Color:{colorName: "灰色",colorValue: "hui se"},
cation :{name:"金属",value:"133"}
},
{
Color:{colorName: "红色",colorValue: "hong se"},
cation :{name:"木制",value:"123"}
},
]
]
// 我想要的数据格式
let list = [
{
discountPrice: 4534,
freight: 12,
sellingPrice: 43535,
skuId: 168,
stockNum: 2141,
Color: {colorName: '灰色', colorValue: 'hui se'},
cation: {name: '金属', value: '133'}
},
{
discountPrice: 342,
freight: 3,
sellingPrice: 4536,
skuId: 654,
stockNum: 345,
Color: {colorName: '红色', colorValue: 'hong se'},
cation: {name: '木制', value: '123'}
}
]
//我最后实现的代码
let list = [];
for(let i =0;i<arr[0].length;i++){
let arr2 = Object.assign({},arr[0][i], arr[1][i],arr[2][i])
list.push(arr2)
}
console.log("list",list);
因为我是以数组arr的第一个下标的长度为准,所以循环从arr[0]开始
码字不易
转载浏览告知
欢迎大家讨论