How to search for a string inside an array of strings with JavaScript?

To search for a string inside an array of strings with JavaScript, we use the find method.

For instance, we write

const strs = ["abc", "def", "ghi", "jkl", "mno"];
const value = "abc";
const str = strs.find((str) => str === value);

to call strs.find with a callback that checks if str in strs is equal to value.

If there is such an entry, then the first instance of str is returned.