I have an array with some of same ID
value as shown in below.
[
{"ID":"126871","total":"200.00","currency":"USD","name":"John"},
{"ID":"126872","total":"2000.00","currency":"Euro","name":"John"},
{"ID":"126872","total":"1000.00","currency":"Euro","name":"John"},
{"ID":"126872","total":"500.00","currency":"USD","name":"John"},
{"ID":"126872","total":"1000.00","currency":"Euro","name":"John"},
]
If the ID
value is duplicate, sum the total value of the same currency
. For the different currency
of same ID
, no need to sum total
.
Here is what I want.
[
{"ID":"126871","total":"200.00","currency":"USD","name":"John"},
{"ID":"126872","total":"4000.00","currency":"Euro","name":"John"},
{"ID":"126872","total":"500.00","currency":"USD","name":"John"}
]
I am stuck with the above problem. I already tried as much as I can. But I got the wrong result. I'm very appreciative for any advice.