Searching for a way to organize the JSON Array with 2 keys and calculate the counts of grouped object key using Javascript.
Seeking a solution specifically in Javascript.
Desired Outcome: the length of the counts object should be limited to 5, showing the total sum of all grouped keys combined.
[
{
"totalCount": 3,
"counts": [0,0,3,0,0],
"productID": "tea1",
"keyVal": "key5",
"trend": "0"
},
{
"totalCount": 4,
"counts": [2,2,0,0,0],
"productID": "tea1",
"keyVal": "key1",
"trend": "0"
},
{
"totalCount": 11,
"counts": [0,5,6,0,0],
"productID": "group1",
"keyVal": "key2",
"trend": "0"
},
{
"totalCount": 616,
"counts": [101,507,8,0,0],
"productID": "group1",
"keyVal": "key1",
"trend": "0"
},
]