How to find if an array contains a specific string in JavaScript/jQuery?

Totally agree with Ian! That’s a great modern approach. But in case you’re dealing with legacy code or older browsers (which I’ve had to wrangle a few times)…

You might want to consider using jQuery’s $.inArray():

if ($.inArray("specialword", categories) !== -1) {
  console.log("Found the string!");
}

This was the standard before ES6 gave us .includes(). It still gets the job done effectively if you’re relying on jQuery elsewhere in your project. So yep, another solid tool for the javascript find string in array task.