Recently, I've been delving into JS high array methods and encountered an array of objects featuring cost categories and values:
[{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 aim is to condense this array by summing the 'amount' values as follows:
[{category: "Bars", amount: 33231}, //31231+2000
{category: "Transport", amount: 3797}, //1297+2500
{category: "Utilities", amount: 12300},
{category: "Education", amount: 21321}]
I attempted using reduce() and forEach(), but have not yet found a solution to resolve the issue. Appreciate any guidance!