Please help to combine object keys values from json arrays by key.
const input=[{"Date":"04/10/2019","Time":"15:35","Title":"Flight -\u00a0Group C","Description":"Arrival 19:40"
},
{"Date":"04/10/2019","Time":"Evening","Title":"Welcome drinks","Description":"In the bar at\u00a0"
},
{"Date":"05/10/2019","Time":"Morning","Title":"Breakfast","Description":"At leisure"
},
{"Date":"05/10/2019","Time":"10:00","Title":"Something Else","Description":"At leisure"
}];
console.log(
Object.values(input.reduce((a, { Date }) => {
if (!a[Date]) a[Date] = { Date, activities: [] };
a[Date].activities.push();
return a;
}, {}))
);
I need a combined object keys values in javascript in the following way:
[
{"date":"04/10/2019","activities":[
{"Time":"15:35","Title":"Flight -\u00a0Group C","Description":"Arrival 19:40"
},
{"Time":"Evening","Title":"Welcome drinks","Description":"In the bar at\u00a0"
}
]
},
{"date":"05/10/2019","activities":[
{"Time":"Morning","Title":"Breakfast","Description":"At leisure"
}
]
}
]
I am trying to get the result with my code but 'activities' are null... I would highly appreciate your help.
Thank you in advance