I am pretty new to JS high array methods and I have an array of objects that contain cost categories and value like this:
[{category: "Bars", amount: 31231},
{category: "Transport", amount: 1297},
{category: "Utilities", amount: 12300},
{category: "Bars", amount: 2000},
{category: "Transport", amount: 2500},
{category: "Education", amount: 21321}]
My goal is to reduce this array and sum the 'amount' values like this:
[{category: "Bars", amount: 33231}, //31231+2000
{category: "Transport", amount: 3797}, //1297+2500
{category: "Utilities", amount: 12300},
{category: "Education", amount: 21321}]
I tried reduce() and and forEach(), but I could not really find a way to solve the issue. Thank you!