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
let filter = ["action", "romance"]; let genres = "action sci-fi romance horror";
this should be true
Advertisement
Answer
As stated by @jabaa, you can use every
and includes
:
const matches = filter.every((word) => genres.includes(word));