Skip to content
Advertisement

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

Advertisement

Answer

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

const matches = filter.every((word) => genres.includes(word));
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement