Suppose I have an array in TypeScript that looks like this:
const array = [
{ id_m: "123",
period: "Q1/22",
amount: 1000
},
{ id_m: "123",
period: "Q1/22",
amount: 500
},
{ id_m: "123",
period: "Q2/22",
amount: 100
},
]
I aim to condense this array by summing up the amounts based on the properties id_m and period. The desired output should be:
const output = [
{ id_m: "123",
period: "Q1/22",
amount: 1500
},
{ id_m: "123",
period: "Q2/22",
amount: 100
}
]
How can I achieve this most effectively?