I'm trying to restructure the data I get from graphql base on its Date value. I will map that array to display some type of feed or a list of the next events. Dates don't carry out any importance here it is just grouping and in sample data, I replaced the long date formating with days to make it easier.
So here is a sample Data:
[{
"__typename": "Session",
"date": "Monday",
"id": "6180da7e1478f62322df638b",
},
{
"__typename": "Session",
"date": "Wednesday",
"id": "6180da7f1478f62322df638c",
},
{
"__typename": "Session",
"date": "Wednesday",
"id": "6180da7f1478f62322df638d",
}]
I'm trying to create a new array with
[
{
"date": "Monday",
"sessions":[
{
"__typename": "Session",
"date": "Monday",
"id": "6180da7e1478f62322df638b",
}
]
},
{
"date": "Wednesday",
"sessions": [
{
"__typename": "Session",
"date": "Wednesday",
"id": "6180da7f1478f62322df638c",
},
{
"__typename": "Session",
"date": "Wednesday",
"id": "6180da7f1478f62322df638d",
}
]
},
]
I have tried array.reduce(), but no luck so far, anybody has any suggestion?