Is there a way to merge objects based on one property and also add missing Days names in the output?
Consider this example:
var array = [
{
"heure1": "14:00",
"heure2": "17:00",
"day": "Sunday",
},
{
"heure1": "08:00",
"heure2": "13:00",
"day": "Sunday",
},
{
"heure1": "14:00",
"heure2": "16:00",
"day": "Monday",
},
{
"heure1": "08:00",
"heure2": "18:00",
"day": "Monday",
},
];
Desired outcome:
var array = [
{
"heure": ["14:00","17:00","08:00","13:00"],
"day": "Sunday",
},
{
"heure": ["14:00","16:00","08:00","18:00"],
"day": "Monday",
},
{
"heure": [],
"day": "Saturday",
},
{
"heure": [],
"day": "Friday",
},
{
"heure": [],
"day": "Thursday",
},
{
"heure": [],
"day": "Wednesday",
},
{
"heure": [],
"day": "Tuesday",
},
];
I have tried various Stack Overflow solutions without success. Any help would be appreciated. Thank you!