I have an array of objects with a specific property that I want to group by. My objective is to create a new array where all the objects have the same properties, but with an additional property that combines all the "value" properties into an array.
Here is the input data along with the desired output. How can I achieve this?
INPUT
[ {
group_by_this_property: 1,
value: 100,
class: 'A',
},
{
group_by_this_property: 1,
value: 101,
class: 'A',
},
{
group_by_this_property: 1,
value: 102,
class: 'A',
},
{
group_by_this_property: 2,
value: 200,
class: 'B',
},
{
group_by_this_property: 2,
value: 201,
class: 'B',
}
]
OUTPUT
[
{
group_by_this_property: 1,
values: [100, 101, 102],
class: 'A',
},
{
group_by_this_property: 2,
values: [200, 201],
class: 'B',
},
]