Hi I would like to know how to check if the exact words contained in an array in Javascript are present in a string, like this
JavaScript
x
3
1
let filter = ["action", "romance"];
2
let genres = "action sci-fi romance horror";
3
this should be true
Advertisement
Answer
As stated by @jabaa, you can use every
and includes
:
JavaScript
1
2
1
const matches = filter.every((word) => genres.includes(word));
2