JavaScript Iterator includes() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

iterator.includes(searchElement) walks the iterator and asks: is this value equal to the one I am looking for? If a match is found, the result is true. If the iterator ends with no match, the result is false.

Equality uses SameValueZero: like ===, except NaN equals NaN, and 0 equals -0. The method consumes the iterator, even when it finds a match early.

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

found     → true (stops early)
not found → false

SameValueZero: NaN equals NaN, 0 equals -0
Consumes the iterator (it is closed after the call).

Syntax

Call it on an iterator and pass the value to search for. You can also skip the first few values with fromIndex.

JavaScript
const nums = [1, 2, 3, 4, 5].values();

console.log(nums.includes(3));   // true
CallWhat it does
iterator.includes(value)Return true if value appears; otherwise false.
iterator.includes(value, fromIndex)Skip the first fromIndex values, then search.
[1, 2, NaN].values().includes(NaN)Find NaN, because SameValueZero treats NaN as equal to itself.

A newer JavaScript Iterator helper method on every iterator, from Iterator.prototype. No import required. Feature-detect before use. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), find(), flatMap(), forEach(), join(), map(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Newer Iterator helper
Iterator.prototype.includes(searchElement)
Iterator.prototype.includes(searchElement, fromIndex)

// searchElement : value to look for
// fromIndex     : optional non-negative start index (default 0)
// returns       : true or false

Parameters

ParameterDescription
searchElementRequired. The value to look for. Compared with each yielded value using SameValueZero (NaN matches NaN, 0 matches -0).
fromIndexOptional. How many values to skip before searching. Must be a non-negative integer, Infinity, or undefined (treated as 0). Negative numbers are not allowed.

Return Value

Return ValueDescription
booleantrue if a matching value is found (after any skipped values). false if the iterator ends without a match. The iterator is closed either way.

JavaScript Examples

Example 1 — Check Whether a Value Is Present

Ask if the number 3 appears in an iterator of 1 through 5.

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const hasThree = nums.includes(3);

console.log("Has 3: " + hasThree);
Try It Yourself

The Try It page first checks that iterator.includes() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.

How It Works

  1. Make an iterator. [1, 2, 3, 4, 5].values() yields each number.
  2. Search for 3. 1 and 2 do not match; 3 does.
  3. Result is true. The search stops at the match, and the iterator is closed.

Example 2 — See That NaN Equals NaN

Show that SameValueZero lets includes() find NaN.

JavaScript
const nums = [1, NaN, 3].values();
const hasNaN = nums.includes(NaN);

console.log("Has NaN: " + hasNaN);
console.log("NaN === NaN: " + (NaN === NaN));
Try It Yourself

The Try It page first checks that iterator.includes() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.

How It Works

  1. Iterator holds NaN. One of the values is NaN.
  2. includes finds it. SameValueZero treats NaN as equal to NaN, so the result is true.
  3. Contrast with ===. Plain NaN === NaN is false, which is why this special rule matters.

Example 3 — Start Searching After fromIndex

Skip the first two values, then look for 2 — it will not be found.

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const found = nums.includes(2, 2);

console.log("Has 2 after skip: " + found);
Try It Yourself

The Try It page first checks that iterator.includes() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.

How It Works

  1. fromIndex is 2. The first two values (1 and 2) are skipped.
  2. Search the rest. The remaining values are 3, 4, and 5.
  3. No match. 2 was already skipped, so includes() returns false.

Browser & Runtime Support

Iterator.prototype.includes() is a newer Iterator helper. It is available in recent Chromium and Firefox builds; Safari support is still catching up. Feature-detect before you rely on it.

✓ Newer · Recent engines

iterator.includes()

Supported in Chrome 153+, Edge 153+, Firefox 154+, Safari 27.3+, Opera 137+ and Node.js 24+. Internet Explorer never got it.

Recent Standard since
Google Chrome 153+ · Desktop & Mobile
Full support
Microsoft Edge 153+ · Chromium based
Full support
Mozilla Firefox 154+ · Desktop & Mobile
Full support
Apple Safari 27.3+ · macOS & iOS
Partial / recent
Opera 137+ · Chromium based
Full support
Samsung Internet Recent · Android
Supported
Android WebView 153+ · Chromium based
Supported
Node.js 24+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
iterator.includes() Recent engines

Bottom line: Feature-detect with typeof Iterator.prototype.includes === "function" (or join). On older engines, convert with Array.from() and use the matching Array method.

Frequently Asked Questions

It returns true if the iterator yields a value equal to the one you pass in, using SameValueZero. Otherwise it returns false. The iterator is consumed.
Yes. SameValueZero treats NaN as equal to NaN, so includes(NaN) can return true. That is different from ===, where NaN === NaN is false.
No. Unlike Array.prototype.includes(), a negative fromIndex is not allowed on iterators, because there is no known length from the end.
No. includes() closes the iterator whether or not a match was found. Make a new iterator if you need another search.
It is a newer helper. Feature-detect with typeof Iterator.prototype.includes !== "function" before you rely on it in older browsers.

Next: join()

Learn how to turn every value from an iterator into one string with a separator.

join() 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.

12 people found this page helpful