JavaScript Array includes() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Membership

What You’ll Learn

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

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.

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.

📝 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.
  • allowed.includes(role) — permission / allow-list checks.

⚡ Quick Reference

GoalCode
Check membershiparr.includes(value)
Search from indexarr.includes(value, fromIndex)
Find NaNarr.includes(NaN) works
Get index insteadarr.indexOf(value)
Mutates array?No

📋 includes() vs indexOf() vs some() vs find()

Pick the method that matches whether you need a boolean, an index, or a custom test.

includes
true / false

Exact value

indexOf
index or -1

Position

some
custom test

Predicate fn

find
element

Return match

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Simple true/false membership tests.

Example 1 — Check If a Value Exists

Test whether the array contains specific numbers.

JavaScript
const numbers = [1, 2, 3, 4, 5];

console.log(numbers.includes(3));
// true

console.log(numbers.includes(10));
// false
Try It Yourself

How It Works

3 is in the array, so the result is true. 10 is not, so the result is false.

Example 2 — Strict Equality (Type Matters)

The number 2 and the string "2" are different values.

JavaScript
const mixed = [1, "2", true];

console.log(mixed.includes("2"));
// true

console.log(mixed.includes(2));
// false
Try It Yourself

How It Works

The array holds the string "2", so includes("2") matches. The number 2 does not match because types differ.

📈 Practical Patterns

fromIndex, NaN, and real-world conditionals.

Example 3 — Start Search with fromIndex

Skip earlier elements by passing a starting index.

JavaScript
const numbers = [1, 2, 3, 2, 5];

console.log(numbers.includes(2));
// true (found at index 1)

console.log(numbers.includes(2, 3));
// true (found at index 3)

console.log(numbers.includes(2, 4));
// false (search starts at index 4)
Try It Yourself

How It Works

With fromIndex 4, only index 4 and beyond are checked. The last 2 at index 3 is skipped.

Example 4 — Finding NaN (Unlike indexOf)

includes() treats NaN as equal to NaN.

JavaScript
const values = [1, NaN, 3];

console.log(values.includes(NaN));
// true

console.log(values.indexOf(NaN));
// -1
Try It Yourself

How It Works

SameValueZero equality lets includes(NaN) succeed. indexOf uses strict equality and never finds NaN.

Example 5 — Allow-List with Strings (Case-Sensitive)

Guard actions when a role or tag must be in an approved list.

JavaScript
const allowedRoles = ["admin", "editor", "viewer"];
const userRole = "editor";

if (allowedRoles.includes(userRole)) {
  console.log("Access granted");
} else {
  console.log("Access denied");
}
// Access granted

console.log(allowedRoles.includes("Editor"));
// false (case-sensitive)
Try It Yourself

How It Works

"editor" matches exactly. "Editor" fails because string comparison is case-sensitive. Normalize with toLowerCase() if you need case-insensitive checks.

🚀 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.

📝 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.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.includes() Excellent

Bottom line: Safe for modern web apps. For IE11, use indexOf !== -1 or a polyfill.

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.

💡 Best Practices

✅ Do

  • Use includes for readable boolean checks
  • Normalize strings if case should not matter
  • Use includes(NaN) instead of indexOf for NaN
  • Pass fromIndex when skipping early matches
  • Use some() for complex predicates

❌ Don’t

  • Expect loose equality (2 vs "2")
  • Assume deep equality for objects
  • Use includes when you need the index
  • Replace filter with manual includes loops unnecessarily
  • Rely on it in IE11 without a fallback

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.includes()

Simple boolean membership tests for arrays.

5
Core concepts
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.

Continue to indexOf()

Learn how to find the position of a value in an array when you need the index, not just true or false.

indexOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful