Data Analysis:
dataSet: [],
models: [
{ id: 1, name: "samsung", seller_id: 1, count: 56 },
{ id: 1, name: "samsung", seller_id: 2, count: 68 },
{ id: 2, name: "nokia", seller_id: 2, count: 45 },
{ id: 2, name: "nokia", seller_id: 3, count: 49 }
]
Desired Output:
dataSet: [
{ id: 1, name: "samsung", count: 124 },
{ id: 2, name: "nokia", count: 94 }
]
This script aims to simplify the data set by removing duplicate id
s:
this.models.forEach(mdl => {
if (!this.dataSet.some(obj => obj.id === mdl.id)) {
this.dataSet.push(mdl);
}
});
However, the challenge lies in summing up the count
values.
Any suggestions on how to achieve this?