// arr 源数组 id 需要分类的目标key let shop = arr.reduce((shop, item) => { shop[item.id] = shop[item.id] ? [...shop[item.id], item] : [item]; return shop; }, {}); console.log(shop);
结果: