Sometimes, we want to check if element is in array with JavaScript.
In this article, we’ll look at how to check if element is in array with JavaScript.
How to check if element is in array with JavaScript?
To check if element is in array with JavaScript, we can use the array includes method.
For instance, we write
if (arr.includes("abc")) {
// ...
}
to call arr.includes with 'abc' to check if the arr array has 'abc' in it.
Conclusion
To check if element is in array with JavaScript, we can use the array includes method.