JavaScript Array includes() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.includes(value) returns true if the value appears at least once, otherwise false. It is a read-only membership test (ES2016). Prefer it over indexOf() !== -1 when you only need yes/no — and when you care about NaN.

Remember
array.includes(value)
array.includes(value, fromIndex)

[1, 2, 3].includes(2)     → true
[1, 2, 3].includes(9)     → false
[NaN].includes(NaN)       → true   // indexOf fails here

SameValueZero (≈ ===, but NaN matches NaN)
does not mutate the array

Syntax

Call array.includes. Start with this line.

JavaScript
array.includes(value, fromIndex = 0)
CallWhat it does
array.includes(value, fromIndex = 0)Primary signature.
array.includes(...)Call with the arguments your case needs.

Built into JavaScript. Call includes(...) on an array instance — no import required.

Library declarations
JavaScript
array.includes(value, fromIndex = 0)

Parameters

ParameterDescription
ArrayRequired. Source to search
valueRequired. Value to look for
fromIndexOptional. Start index; negative counts from the end

Return Value

Return ValueDescription
*true or false

JavaScript Examples

Example 1 — Basic Membership Check

Ask whether a value exists — get a clear boolean.

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

  1. Build the array. Numbers 1 through 5.
  2. Look for 3. It is present → true.
  3. Look for 10. Not present → false.
  4. No index math. You do not need to compare with -1.

Example 2 — Start Later with fromIndex

Skip earlier elements when you only care about a suffix of the array.

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

console.log(numbers.includes(2));     // true  (index 1)
console.log(numbers.includes(2, 3));  // true  (index 3)
console.log(numbers.includes(2, 4));  // false
Try It Yourself

How It Works

  1. Default search. Finds the first 2 near the start.
  2. Start at 3. Skips the first 2; still finds the later one.
  3. Start at 4. Only 5 remains → false.
  4. Negative fromIndex. Counts from the end, same idea as relative offsets.

Example 3 — includes vs indexOf (and NaN)

Use includes for membership; use indexOf when you need the index. Prefer includes for NaN.

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

console.log(values.includes(NaN));  // true
console.log(values.indexOf(NaN));   // -1

console.log(values.includes(1));    // true
console.log(values.indexOf(1));     // 0
Try It Yourself

How It Works

  1. includes finds NaN. SameValueZero treats NaN as equal to itself.
  2. indexOf misses NaN. Because NaN === NaN is false.
  3. Normal values agree. Both see 1; indexOf also gives position 0.
  4. Pick by need. Boolean → includes; index → indexOf.

Browser & Runtime Support

Array.prototype.includes() is part of ES2016 (ES7). It has been available in evergreen browsers and Node.js for years.

✓ Baseline · ES2016

Array.prototype.includes()

Supported in Chrome 47+, Firefox 43+, Safari 9+, Edge 14+, and Node.js 6+. Not available in Internet Explorer without a polyfill.

98% 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 almost all modern web apps and Node LTS releases. For IE11, feature-detect with if ("includes" in Array.prototype) or use a polyfill / indexOf() !== -1 (with care for NaN).

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 and does not change the array.
includes() returns true or false. indexOf() returns the index (0 or higher) or -1 if not found. includes() also finds NaN correctly; indexOf() does not.
It uses SameValueZero comparison — like ===, except NaN equals NaN. The number 2 and the string "2" are still different.
fromIndex is optional. It sets where the search starts. Negative values count from the end of the array (like relative offsets).
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 needs a polyfill.

Next: indexOf()

Find the index of a value — or get -1 when it is missing.

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.

11 people found this page helpful