How to Check if an Array Contains a Value in JavaScript with includes
array.includes(value) gives true when one of the array's items is exactly value, and false otherwise. It compares whole items and is case-sensitive. A string has an includes method too, but it searches text, so check that you really have an array before you rely on it.
Syntax
<array>.includes(<value>)
<array>.includes(<value>, <fromIndex>)
| Part | What it does |
|---|---|
<array> | The array to search. |
<value> | The value to look for. An item matches when it's the same value: 'green' matches 'green', but not 'Green' or 'gre'. |
<fromIndex> | Optional. The index to start searching at. A negative number counts back from the end. |
It returns true or false. MDN's includes reference: "The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate."
The Example
The example searches an array of three colours for 'green', for 'Green' with a capital letter, for the start of a word, 'gre', and for 'red' starting at index 1. The last line calls includes on the string 'not-green' to show how a string's includes differs.
Prerequisites
- Node.js. This guide uses Node.js 26.13.1.
Step 1: Write the Code
Create a file named main.js:

const colors = ['red', 'green', 'blue'];
console.log(colors.includes('green'));
console.log(colors.includes('Green'));
console.log(colors.includes('gre'));
console.log(colors.includes('red', 1));
const text = 'not-green';
console.log(text.includes('green'));
Step 2: Run It
node main.js
true
false
false
false
true

The command is the same in zsh, bash and PowerShell.
What Happened
colors.includes('green')istrue, because one item is exactly'green'.'Green'isfalse: the comparison is case-sensitive.'gre'isfalse:includescompares whole items, not the text inside them.colors.includes('red', 1)isfalse. The search started at index 1,'green', and'red'is at index 0.- The string
'not-green'gavetruefor'green'. That'sString.prototype.includes, which looks for text inside the string. If code expects an array of roles and gets the string'not-green', a check for'green'passes.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Calling includes on a value that may be a string | It searches text, so 'not-green'.includes('green') is true | Check Array.isArray(value) first |
Searching an array of numbers with a string, [1, 2, 3].includes('2') | false, because '2' and 2 aren't the same value | Convert first, for example Number(input) |
Searching for an object, [{ a: 1 }].includes({ a: 1 }) | false: two objects match only when they're the same object | Use some with a comparison: items.some((item) => item.a === 1) |
Calling includes on null or undefined | TypeError: Cannot read properties of null (reading 'includes') | Check the value is an array first |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
includes says an item is missing, but you can see it | A difference in case, spacing or type | Compare the exact values, for example with JSON.stringify |
| A check passes for a value that shouldn't pass | The value was a string, not an array | Add Array.isArray to the check |
FAQ
What's the difference between includes and indexOf?
includes gives true or false, while indexOf gives the item's index or -1. They also differ on NaN: [NaN].includes(NaN) is true, but [NaN].indexOf(NaN) is -1. MDN explains that includes compares with the SameValueZero algorithm, which treats NaN as equal to itself.
What does a negative fromIndex do?
It counts back from the end: colors.includes('blue', -1) searches only the last item and gives true, and colors.includes('red', -1) gives false.
Conclusion
includes answers "is this exact value one of the items?" in one call. Make sure the value really is an array first, because a string's includes searches text and can pass a check it shouldn't.
Additional Resources
- Array.prototype.includes(), on MDN.
- String.prototype.includes(), on MDN.
