let firstArray = [
{
id: 1,
ware: 'Test',
price: 122.3
},
{
id: 2,
ware: 'Test',
price: 122.3
},
{
id: 1,
ware: 'Fre',
price: 133.3
}
];
let resultArray = [
{
id: 1,
offers: [
{
id: 1,
ware: 'Test',
price: 122.3
},
{
id: 1,
ware: 'Fre',
price: 133.3
}
]
},
{
id: 2,
offers: [
{
id: 2,
ware: 'Test',
price: 122.3
}
]
}
];
const result = Object.values(arr.reduce((acc, n) => {
const group = acc[n.id] = acc[n.id] || { id: n.id, offers: [] };
group.offers.push(n);
return acc;
}, {}));