I am trying to loop through an array of objects with multiple dates and other data. I want the dates to be stored in the start and the rest of the data to be stored in an array data[]. In cases the date is similar for any two objects, I want to push all the data(except for the date) into the data[]
Original data:
[{
start: "2019-08-23",
title: "Week 5 Dispensing Tutorial 3 Quiz ",
type: "Lecture",
},
{
start: "2019-08-25",
title: "Week 5 Dispensing Tutorial 3 Quiz ",
type: "Tutorial",
},
{
start: "2019-08-25",
title: "Week 5 Dispensing Tutorial 3 Quiz ",
type: "Lecture",
}]
Expected Output:
[{
start: "2019-08-23",
data: [{ title: "Week 5 Dispensing Tutorial 3 Quiz", type: "Lecture" }]
},
{
start: "2019-08-25",
data: [{ title: "Week 5 Dispensing Tutorial 3 Quiz", type: "Tutorial" }, {title: "Week 5 Dispensing Tutorial 3 Quiz", type: "Lecture" }]
}]
I have tried the following code, but it doesnt handle the duplication:
var result[] = ITEMS.map(ITEMS => ({
start: ITEMS.start,
data: [
{
title: ITEMS.title,
type: ITEMS.type
}
]
}));