I have an Array of Objects where I'm trying to combine a couple of the properties and then return a new Array of Objects. Below is an example of the structure of the original Array of Objects:
[
{
"memID": "180",
"memType": "Movie",
"date": {
"month": 5,
"year": 1980
},
"favourite": null,
"public": null,
"music": [],
"movie": [
{
"poster": "https://image.tmdb.org/t/p/original//7BuH8itoSrLExs2YZSsM01Qk2no.jpg"
}
],
"tvshow": [],
"game": []
},
{
"memID": "65",
"memType": "Game",
"date": {
"month": 5,
"year": 1980
},
"favourite": null,
"public": null,
"music": [],
"movie": [],
"tvshow": [],
"game": [
{
"boxArt": "https://images.igdb.com/igdb/image/upload/t_1080p/co1hvj.jpg"
}
]
},
{
"memID": "178",
"memType": "Movie",
"date": {
"month": 5,
"year": 1980
},
"favourite": null,
"public": null,
"music": [],
"movie": [
{
"poster": "https://image.tmdb.org/t/p/original//5xcXvTErivIgRchsaw9qaT3NflE.jpg"
}
],
"tvshow": [],
"game": []
},
]
What I would like to do is to return a new Array of Objects that groups the data by monthYear by combining both the month and year properties, for example:
[
{
"monthYear": {
"5-1980": {
{
"memID": "180",
"memType": "Movie",
"favourite": null,
"public": null,
"music": [],
"movie": [
{
"poster": "https://image.tmdb.org/t/p/original//7BuH8itoSrLExs2YZSsM01Qk2no.jpg"
}
],
"tvshow": [],
"game": []
},
{
"memID": "65",
"memType": "Game",
"favourite": null,
"public": null,
"music": [],
"movie": [],
"tvshow": [],
"game": [
{
"boxArt": "https://images.igdb.com/igdb/image/upload/t_1080p/co1hvj.jpg"
}
]
},
{
"memID": "178",
"memType": "Movie",
"favourite": null,
"public": null,
"music": [],
"movie": [
{
"poster": "https://image.tmdb.org/t/p/original//5xcXvTErivIgRchsaw9qaT3NflE.jpg"
}
],
"tvshow": [],
"game": []
},
}
}
}
]
I've been trying to flatten the Array and then restructure it but I haven't been able to work out the best approach. I have tried .flat(), .flatMap() and a few other methods but haven't had any success.