注意: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)

