Categories
JavaScript Answers

How to check if element is in array with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *