I've researched about it, i tried these so far :
Merge javascript objects in array with same key
Knex/SQL: Merge one to many join in one object
Merge objects with same id in array
But i couldn't success to merge.
Here is my data :
const data = [
{
"id": 1,
"movie_title": "Extraction",
"imdb": 6.7,
"length": "1h 56min",
"movie_image": "https://i.imgur.com/JljBVho.jpg",
"director": "Sam Hargrave",
"stars": "Chris Hemsworth, Bryon Lerum, Ryder Lerum",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": "action"
},
{
"id": 1,
"movie_title": "Extraction",
"imdb": 6.7,
"length": "1h 56min",
"movie_image": "https://i.imgur.com/JljBVho.jpg",
"director": "Sam Hargrave",
"stars": "Chris Hemsworth, Bryon Lerum, Ryder Lerum",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": "thriller"
},
{
"id": 2,
"movie_title": "The Old Guard",
"imdb": 6.7,
"length": "2h 5min",
"movie_image": "https://i.imgur.com/PSYB2RK.jpg",
"director": "Gina Prince-Bythewood",
"stars": "Charlize Theron, KiKi Layne, Matthias Schoenaerts",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": "action"
},
{
"id": 2,
"movie_title": "The Old Guard",
"imdb": 6.7,
"length": "2h 5min",
"movie_image": "https://i.imgur.com/PSYB2RK.jpg",
"director": "Gina Prince-Bythewood",
"stars": "Charlize Theron, KiKi Layne, Matthias Schoenaerts",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": "adventure"
},
{
"id": 2,
"movie_title": "The Old Guard",
"imdb": 6.7,
"length": "2h 5min",
"movie_image": "https://i.imgur.com/PSYB2RK.jpg",
"director": "Gina Prince-Bythewood",
"stars": "Charlize Theron, KiKi Layne, Matthias Schoenaerts",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": "fantasy"
}
]
And what i want to do is :
const data = [
{
"id": 1,
"movie_title": "Extraction",
"imdb": 6.7,
"length": "1h 56min",
"movie_image": "https://i.imgur.com/JljBVho.jpg",
"director": "Sam Hargrave",
"stars": "Chris Hemsworth, Bryon Lerum, Ryder Lerum",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": ["action","thriller"]
},
{
"id": 2,
"movie_title": "The Old Guard",
"imdb": 6.7,
"length": "2h 5min",
"movie_image": "https://i.imgur.com/PSYB2RK.jpg",
"director": "Gina Prince-Bythewood",
"stars": "Charlize Theron, KiKi Layne, Matthias Schoenaerts",
"total_season": null,
"production_year": 2020,
"statu_title": "movie",
"genre_title": ["action","adventure","fantasy"]
}
]
So basically i want to merge objects by id, and convert genre_title to an array. Actually I couldn't understand reduce and filter methods even though I researched about them. (Probably I don't even need lodash...) Thank you!