Skip to main content

Command Palette

Search for a command to run...

How to check if an array includes a value

Published
1 min read
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.