I have an array like this :
[
{
"orderId": 1,
"orderDate": "2021-04-28T08:20:58Z",
"status": "Confirmed",
"sellerName": "Chris Gilmour",
"revenue": 2316.49
},
{
"orderId": 2,
"orderDate": "2020-12-19T12:30:18Z",
"status": "Confirmed",
"sellerName": "Alanna Sumner",
"revenue": 2928.88
},
{
"orderId": 4,
"orderDate": "2020-12-24T08:00:09Z",
"status": "Confirmed",
"sellerName": "Beth North",
"revenue": 1550.19
},
{
"orderId": 5,
"orderDate": "2021-06-06T04:40:48Z",
"status": "Confirmed",
"sellerName": "Laura Ponce",
"revenue": 35.5
},
{
"orderId": 8,
"orderDate": "2021-08-27T05:13:40Z",
"status": "Canceled",
"sellerName": "Blade Newman",
"revenue": 2957.29
},
{
"orderId": 9,
"orderDate": "2020-12-26T08:07:57Z",
"status": "Confirmed",
"sellerName": "Alanna Sumner",
"revenue": 2164.75
},
{
"orderId": 10,
"orderDate": "2021-04-23T18:44:19Z",
"status": "Confirmed",
"sellerName": "Blade Newman",
"revenue": 2287.55
}
]
I want the new Array to be :
[
{
"sellerName": "Blade Newman",
"totalRevenue": 5244.84
},
{
"sellerName": "Alanna Sumner",
"totalRevenue": 5093.63
},
{
"sellerName": "Chris Gilmour",
"totalRevenue" : 2316.49
},
{
"sellerName": "Beth North",
"totalRevenue": 1550.19
}
]
So I want the array to be grouped by sellerName, the amount sold summed up and ordered By sellers with the most total sales.
I tried to solve this by using forEachs and reduces but I failed, if anyone can help me that would be great.
Thanks in advance.