How can you filter movie title on the basis of Genre item in array?
const result = [
{
title: "Mad Max: Fury Road",
genre: ["Action", "Adventure", "Sci-Fi"],
},
{
title: "The Hunger Games: Mockingjay Part 1",
genre: ["Adventure", "Thriller"],
},
{
title: "Jurassic World",
genre: ["Action", "Adventure", "Sci-Fi"],
},
{
title: "Everest",
genre: ["Drama", "Thriller"],
},
{
title: "Insurgent",
genre: ["Adventure"],
},
{
title: "Sicario",
genre: ["Action", "Crime", "Drama"],
},
];
Suppose if I want to filter movie title name on the basis of genre eg: "Sci-Fi"
then it should return array of movie titles eg: ["Mad Max: Fury Road", "Jurassic World"]
.
Tried various combinations of map and filter but not working.
const newResult = result
.map((curr) => curr.genre.filter((ele) => ele === search))
.filter((ele) => ele);