What is the best way to reduce this array of objects to get the desired result?
const arr = [
{
"id": "561",
"count": "1",
"month": 7
},
{
"id": "561",
"count": "1",
"month": 7
},
{
"id": "561",
"count": "-1",
"month": 8
},
{
"id": "561",
"count": "1",
"month": 9
},
{
"id": "561",
"count": "-1",
"month": 9
}
]
As you can see the id matches and some of the months match. What I would like to achieve is something along the lines of:
[
{
"id": "561",
"count": 2
"month": 7
},
{
"id": "561",
"count": -1,
"month": 8
},
{
"id": "561",
"count": 0,
"month": 9
}
]
I'm basically trying to get the total count by month per id.