I have an array as follows:
const arr = [{
name: 'XYZ',
values: [1, 2, 3]
}, {
name: 'ABC',
values: [5]
}, {
name: 'XYZ',
values: [4, 5, 6]
}, {
name: 'ABC',
values: [8, 9]
}];
I'm using underscore js and trying to transform as follows:
const result = [{
name: 'XYZ',
values: [1, 2, 3, 4, 5, 6]
}, {
name: 'ABC',
values: [5, 8, 9]
}]
I was able to group by name and trying to loop in, but not sure how do I merge values. So far this is what I've done:
_.chain(arr)
.groupBy((item) => item.name)
// I don't know what to do here
.value();