Skip to main content

How to check if an array includes a value

Updated 1 min readMarkdown
How to check if an array includes a value

To easily know if an array includes a value we can use the includes() method:

let items = [ "Computer", "Monitor" ];

items.includes("computer"); // false

items.includes("Computer"); // true

As you can see it is case sensitive. And you can check for example numbers too:

let numbers = [ 4, 10, 27 ];

numbers.includes(2); // false

numbers.includes(10); // true

It will return true if the value is found within the array or false if it's not.

About the author

  • 💻 Frontend Developer. 📱 Tech passionate. 🎲 Board Game lover. 🏈 Football rookie.

No comments yet. Be the first to comment.