The includes() method checks whether an array contains a value and returns true or false. It uses strict equality (with special NaN handling), supports an optional fromIndex, and is clearer than indexOf() !== -1. This tutorial covers syntax, five examples, and comparisons with related methods.
01
Syntax
includes(val)
02
Boolean
true / false
03
Strict
===
04
NaN
Finds NaN
05
fromIndex
Start offset
06
ES2016
Modern JS
Fundamentals
Introduction
Before includes(), developers often wrote arr.indexOf(value) !== -1 to test membership. The includes() method makes that intent obvious and returns a clean boolean.
Use it in conditionals, guards, and validation—anywhere you need a yes/no answer about whether a value appears in an array.
Concept
Understanding the includes() Method
array.includes(searchElement, fromIndex?) scans the array and returns true as soon as a match is found. If no match exists, it returns false.
Comparisons use the SameValueZero algorithm: like strict equality, but NaN equals NaN. That is a key advantage over indexOf(), which cannot find NaN.
💡
Beginner Tip
includes() does not mutate the array. It only reads values. For complex conditions (e.g. “any item > 10”), use some() instead.
Foundation
📝 Syntax
General form of Array.prototype.includes:
JavaScript
array.includes(searchElement, fromIndex)
Parameters
searchElement — the value to look for.
fromIndex — optional; index to start searching (default 0). Negative values count from the end.
Return value
true if the element is found at least once.
false otherwise.
Original array unchanged.
Common patterns
arr.includes(42) — basic membership test.
arr.includes(item, 2) — search from index 2 onward.
if (tags.includes("js")) { ... } — conditional logic.
"editor" matches exactly. "Editor" fails because string comparison is case-sensitive. Normalize with toLowerCase() if you need case-insensitive checks.
Applications
🚀 Common Use Cases
Permission checks — verify role or feature flags in an allow-list.
Form validation — ensure selected option is in valid choices.
Tag filtering — check if a post has a specific tag.
Game logic — test inventory for an item ID.
Config guards — skip code paths when env is not in supported list.
Replacing indexOf — cleaner includes instead of indexOf !== -1.
🧠 How includes() Runs
1
Resolve fromIndex
Default 0; clamp negative indices to array bounds.
Start
2
Compare elements
SameValueZero check against searchElement.
Match
3
Short-circuit
Return true immediately on first match.
Found
4
✅
Return boolean
false if no match after full scan.
Important
📝 Notes
Returns true or false only—not an index.
Uses SameValueZero (=== plus NaN handling).
String searches are case-sensitive.
Objects match by reference, not deep equality.
For custom logic, use some() with a predicate.
ES2016—polyfill or indexOf for IE11.
Compatibility
Browser & Runtime Support
Array.prototype.includes() was added in ES2016 (ES7). It is available in all evergreen browsers and modern Node.js versions.
✓ Baseline · ES2016
Array.prototype.includes()
Supported in Chrome 47+, Firefox 43+, Safari 9+, Edge (all versions), and Node 6+. Not available in Internet Explorer without a polyfill.
96%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.includes()Excellent
Bottom line: Safe for modern web apps. For IE11, use indexOf !== -1 or a polyfill.
Wrap Up
Conclusion
includes() is the clearest way to ask “is this value in the array?” Remember strict typing, case-sensitive strings, and the special NaN behavior that sets it apart from indexOf().
When you need the position of a match, continue to indexOf() next.
Replace filter with manual includes loops unnecessarily
Rely on it in IE11 without a fallback
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.includes()
Simple boolean membership tests for arrays.
5
Core concepts
📝01
Syntax
arr.includes(val)
API
✅02
Boolean
true / false.
Return
📐03
Strict
Type matters.
Compare
∞04
NaN
Finds NaN.
Special
📍05
fromIndex
Start offset.
Option
❓ Frequently Asked Questions
includes() returns true if the array contains the search value at least once, otherwise false. It is a simple boolean membership test.
includes() returns true or false. indexOf() returns the index (0 or higher) or -1 if not found. includes() also correctly finds NaN; indexOf() does not.
Yes. includes() compares with === (SameValueZero for NaN). The number 2 and the string "2" are different values.
fromIndex is optional. It sets where the search starts. Negative values count from the end of the array.
No. includes() only reads the array and returns a boolean. The original array is unchanged.
includes() is ES2016 (ES7). It works in all modern browsers and Node.js 6+. Internet Explorer does not support it without a polyfill.
Did you know?
Strings also have an includes() method for substring search. "hello".includes("ell") returns true. Array includes checks whole elements, not substrings inside them.