I have a large array filled with various objects structured like:
[
{
"type": "bananas",
"count": 15
},
{
"type": "kiwis",
"count": 20
},
{
"type": "bananas",
"count": 5
},
{
"type": "strawberries",
"count": 10
},
{
"type": "strawberries",
"count": 25
}
]
My goal is to iterate through the array and combine counts for objects with matching types. Using the provided example, the desired output would be:
[
{
"type": "bananas",
"count": 20
},
{
"type": "kiwis",
"count": 20
},
{
"type": "strawberries",
"count": 35
},
]
If anyone has any tips or guidance on how to achieve this, I would really appreciate it.