I have an array like this:
let purchases = [{
year: 2019,
sum: 3000
},
{
year: 2019,
sum: 5500
},
{
year: 2020,
sum: 2300
}
]
I need to calculate the value of the sum for each year, that is, to get the following result.
{"2019": 8500, "2020": 2300}
How can I do that?