Categories
JavaScript Answers

How to check if an array includes a value in JavaScript?

Spread the love

To check if an array includes a value in JavaScript, we use the includes method.

For instance, we write

console.log(["joe", "jane", "mary"].includes("jane"));

to call includes to check if 'jane' is in the ["joe", "jane", "mary"] array.

Since 'jane' is in the array, true is returned.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.