Sometimes, we want to check for multiple conditions for JavaScript .includes() method.
In this article, we’ll look at how to check for multiple conditions for JavaScript .includes() method.
How to check for multiple conditions for JavaScript .includes() method?
To check for multiple conditions for JavaScript .includes() method, we use the array some
method.
For instance, we write
const str1 = "hi hello, how do you do?";
const conditions = ["hello", "hi", "howdy"];
const test1 = conditions.some((el) => str1.includes(el));
to call conditions.some
with a callback to see if str1
has any one of 'hello'
, 'hi'
and 'howdy'
in the str1
string.
We call str1.includes
to see if the el
entry in conditions
is in the string.
Conclusion
To check for multiple conditions for JavaScript .includes() method, we use the array some
method.