let listA = [
{
"activityCenterUrl": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/2933c696260e57505f76b39949c93cea.png",
"coverChart": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/15737ffb1f4466c0196c07227eef82f6.png",
"createtime": 1627464437000,
"endTime": 1630252800000,
"userId": 609,
"name": "011",
"startTime": 1629216000000,
},
{
"activityCenterUrl": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/2933c696260e57505f76b39949c93cea.png",
"coverChart": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/15737ffb1f4466c0196c07227eef82f6.png",
"createtime": 1627464437000,
"endTime": 1630252800000,
"userId": 610,
"name": "022",
"startTime": 1629216000000,
},
{
"activityCenterUrl": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/2933c696260e57505f76b39949c93cea.png",
"coverChart": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/15737ffb1f4466c0196c07227eef82f6.png",
"createtime": 1627464437000,
"endTime": 1630252800000,
"userId": 611,
"name": "0333",
"startTime": 1629216000000,
},
]
let listB = [
{
"userId": 609,
"goodsList": [
{
"goodsId": 14992,
"goodsPrice": 18383,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/13/21051311081811ea7b3aea0e4b2b.jpg",
"goodsTitle": "哈哈哈哈哈家",
"priority": 1,
"userId": 5016095
},
{
"goodsId": 14949,
"goodsPrice": 88888,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/03/19/2103191531419bcf4cae1a01492a.jpg",
"goodsTitle": "疑是地上霜",
"userId": 5016095
},
{
"goodsId": 14991,
"goodsPrice": 88888,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/13/210513110731d455ead354714f8a.jpg",
"goodsTitle": "鱼游濠上好多好多话亟待解决的家",
"userId": 5016095
}
]
},
{
"userId": 610,
"goodsList": [
{
"goodsId": 14951,
"goodsPrice": 50,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/03/20/210320112817b3022efd4f7141fd.jpeg",
"goodsTitle": "The",
"priority": 1,
"userId": 707355980
}
]
},
{
"userId": 611,
"goodsList": [
{
"goodsId": 16103,
"goodsPrice": 1997,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/17/210517160445794576b7e3ed48ce.jpeg",
"goodsTitle": "444",
"priority": 1,
"userId": 7833518
},
{
"goodsId": 16104,
"goodsPrice": 0.1,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/17/210517160518f2a46297692c4f55.jpeg",
"goodsTitle": "5555",
"priority": 2,
"userId": 7833518
},
{
"goodsId": 16105,
"goodsPrice": 673,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/17/21051716055471893b485b6a4f0c.jpeg",
"goodsTitle": "666",
"priority": 3,
"userId": 7833518
}
]
}
]
/***
* 写个function
* 实现将两个数组对象中userId为同一个的,拼接成一个大的数组。
* 期望如:
* newList[
* {
* "activityCenterUrl": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/2933c696260e57505f76b39949c93cea.png",
"coverChart": "http://chuangshicdn.file.m.mvbox.cn/upload/ga/image/15737ffb1f4466c0196c07227eef82f6.png",
"createtime": 1627464437000,
"endTime": 1630252800000,
"userId": 609,
"name": "011",
"startTime": 1629216000000,
"goodsList": [
{
"goodsId": 14992,
"goodsPrice": 18383,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/13/21051311081811ea7b3aea0e4b2b.jpg",
"goodsTitle": "哈哈哈哈哈家",
"priority": 1,
"userId": 5016095
},
{
"goodsId": 14949,
"goodsPrice": 88888,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/03/19/2103191531419bcf4cae1a01492a.jpg",
"goodsTitle": "疑是地上霜",
"userId": 5016095
},
{
"goodsId": 14991,
"goodsPrice": 88888,
"goodsPic": "http://file.m.mvbox.cn/upload/mobile/familyMatch/21/05/13/210513110731d455ead354714f8a.jpg",
"goodsTitle": "鱼游濠上好多好多话亟待解决的家",
"userId": 5016095
}
]
* }
* ]
*/
function linkArrs() {
let obj = listA.map((item,index) => {
return {...item, ...listB[index]};
});
console.log(obj)
}
linkArrs();
console