I have an array of objects that I am trying to group together based on similar dates. For example, this is the array of objects that I start with:
var array = [
{
startDate: "2018-11-23",
name: "Enrollment",
place: "room 2"
},{
startDate: "2018-11-23",
name: "Breakfast",
place: "break room"
},{
startDate: "2019-11-15",
name: "Training",
place: "room 10"
}];
I've tried creating a for
loop that iterates over each item in the array to see if the startDate matches any other startDates in my object but Im coming up short because of just a misunderstanding of how the for loop is supposed to iterate over an array and then assign an object within an object to keep 'name' and 'place' associated with each other.
What I need to have happen is a new object that contains any shared dates as the object's key with 'place' still associated to 'name'. This is my desired outcome from my starting array:
var output = [
{
startDate: "2018-11-23",
event: {name: "Enrollment"
place: "room 2"}
event2: {name: "Breakfast"
place: "room 10"}
},{
startDate: "2019-11-15",
name: "Training"
}];