i have the following array instance
this.array=[{id:"121",score:"5",createdOn:"2022-05-17T19:52:23.6846702+00:00"}
{id:"121",score:"8",createdOn:"2022-05-19T13:00:00.6846702+00:00"}
{id:"122",score:"7",createdOn:"2022-04-11T08:00:00.6846702+00:00"}
{id:"121",score:"1",createdOn:"2022-03-12T12:00:00.6846702+00:00"}
]
how do i some the values with a matching id and month. for example my ouput should be
newArray=[{id:"121",score:13,month:"May"}
{id:"122",score:7,month:"April"}
{id:"121",score:1,month:"March"}
]
i tried something like this
this.array.forEach(item => {
var obj = {}
if (obj.hasOwnProperty(item.id)) {
obj["id"] = obj[item.id] + parseFloat(item.score);
}
else {
obj["id"] = parseFloat(item.score);
}
this.newArray.push(obj);
});
But it didnt work and i dont know how to check the month