Skip to content

How to check if the exact words contained in an array are present in a string in Javascript [closed]

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

Answer

As stated by @jabaa, you can use every and includes:

const matches = filter.every((word) => genres.includes(word));