a
.let dataAr = [{ a: 5, b: 60 }, { a: 5, b: 70 } ];
function groupData(dar) {
const result = dar.reduce((acc, cur) => {
const index = acc.findIndex(item => cur.a === item.a)
if (index !== -1) {
acc[index].groups.push(cur.b);
} else {
return acc.concat({
a: cur.a,
groups: [
cur.b
]
})
}
})
return result;
}
console.log(groupData(dataAr));
Object.values(arr.reduce((acc, { a, b }) => (
(acc[a] ??= { a, items: [] }).items.push(b),
acc
), {}))