I have an array of below objects
[
{
"date": "2021-07-24",
"model": "Benz",
"bookings": 3
},
{
"date": "2021-07-24",
"model": "BMW",
"bookings": 4
},
{
"date": "2021-07-24",
"model": "Audi",
"bookings": 1
},
{
"date": "2021-07-25",
"model": "Benz",
"bookings": 5
},
{
"date": "2021-07-25",
"model": "BMW",
"bookings": 7
},
{
"date": "2021-07-25",
"model": "Audi",
"bookings": 3
}
]
How do I convert the same after grouping as the below one in js?
Expected:
[
{
"date": "2021-07-24",
"Benz": 3,
"BMW": 4,
"Audi": 1
},
{
"date": "2021-07-25",
"Benz": 5,
"BMW": 7,
"Audi": 3
}
]
Idea on implementing it would be much helpful. Tried implementing a different approach of grouping as referred here
But the above case mentioned as expected output suits the purpose well