JavaScript Includes
includes() checks whether an array contains a given value and returns true or false. Comparison uses strict equality, so it works for primitives (numbers, strings, booleans) but not for object contents.
Syntax
arr.includes(2) Examples
| Input | Arguments | Output |
|---|---|---|
| [1, 2, 3] | 2 | true |
| ["a", "b"] | 'z' | false |
When to use it
- Check a whitelist or blacklist of values.
- Avoid duplicates before pushing a value.
Gotchas
- Objects and arrays are compared by reference, not by content: [{a:1}].includes({a:1}) is false.
- Unlike indexOf(), includes() finds NaN.
Try it live
Type your input and see Includes transform it instantly.
Want to go further? Chain Includes with other functions, pipe one output into the next and watch your data transform in the visual Playground.