注意:arr1 是基础 把arr2合并到arr1中 ,汇成一个总的arrs 这个arr1中的id 和 arr2中的periodId 是一一对应的。
let arr1 = [
{id:64,period:"10:00"},
{id:65,period:"12:00"},
{id:66,period:"14:00"},
{id:67,period:"18:00"},
]
let arr2 = [
{
period:'10:00',
periodId: 64,
products:[
{
goodName: "套餐测试A-001",
goodSn: "1368017317954457600",
id: 252,
limitedNum: 1,
productId: 1658,
remark: null,
seckillPeriodId: 64,
seckillPrice: 1,
seckillStock: 1,
skuId: 2947,
status: 4,
stock: 97,
unitPrice: 100,
}
]
}
]
const arrs = arr1.map(item => {
const data = arr2.find(i => item.id == i.periodId)
return {
...item,
...data,
products: data ? data.products : []
}
})
console.log(arrs)