In my current array, there are multiple objects, each containing an array property. The array within each object holds different genres associated with a movie.
const films = [
{
name: 'Ant-Man and the Wasp',
genre: ['Action' , 'Adventure' , 'Sci-Fi' , 'Comedy']
},
{
name: 'Sorry to Bother You',
genre: ['Comedy' , 'Fantasy']
},
{
name: 'Jurassic World: Fallen Kingdom',
genre: ['Action' , 'Adventure' , 'Sci-Fi'],
},
{
name: 'Incredibles 2',
genre: ['Action' , 'Crime' , 'Drama' , 'Thriller']
},
{
name: 'Deadpool 2',
genre: ['Action' , 'Adventure' , 'Comedy']
}
];
My goal is to iterate through the objects in the array and identify matches based on genres. However, the code I'm currently using doesn't seem to be producing the expected results. Is there a better way to identify matches between objects based on their genres?
for (let i = 0; i < films.length; i++) {
let film = films[i];
let genres = film.genre;
for (let j; j < genres.length; j++) {
if (genres[j] == "Action") {
console.log('Match');
} else {
console.log('No Match');
}
}
}