1 回答
TA贡献1788条经验 获得超4个赞
您可以使用数组归约方法来做到这一点。
const data = [
{
'Row Labels': '37383783738',
'ProdCode&Desc': '8H9H89 Homestyle cinnamon cake (200g) 8x120',
},
{
'Row Labels': '37383783738',
'ProdCode&Desc': '9HD063 Goodness me! Chargrilled bites (20g) 6x30',
},
{
'Row Labels': '83322223733',
'ProdCode&Desc': '39HSH02 MDS Chargrilled Hot & Spicy (40g) 2x30',
},
{
'Row Labels': '83322223733',
'ProdCode&Desc': '93JSHS Treasured battered fillet (120g) 6x30',
},
];
const ret = Object.values(
data.reduce((prev, c) => {
const p = prev;
const key = c['Row Labels'];
if (!p[key]) p[key] = { ...c };
else
p[key] = {
...p[key],
'ProdCode&Desc': (p[key]['ProdCode&Desc'] += `; ${c['ProdCode&Desc']}`),
};
return p;
}, {})
);
console.log(ret);
添加回答
举报