I have an array of objects with some information. Lines with the same color and size, I want to make a total sum and delete the duplicated lines, that is, for each color and size equal, I only want to get one line.
My object array
data = [
{
tam: 'S',
color: 'blue',
total: 5
},
{
tam: 'S',
color: 'blue',
total: 10
},
{
tam: 'S',
color: 'blue',
total: 20
},
{
tam: 'M',
color: 'blue',
total: 5
},
{
tam: 'L',
color: 'blue',
total: 5
}
];
The desired output
data = [
{
tam: 'S',
color: 'blue',
total: 35
},
{
tam: 'M',
color: 'blue',
total: 5
},
{
tam: 'L',
color: 'blue',
total: 5
}
];