JavaScript Iterator every() Method

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

Definition

iterator.every(callback) walks each value from the iterator and asks your function: does this value pass the test? If every value passes, the result is true. If one value fails, the result is false right away.

The method consumes the iterator. After every() finishes (or stops early), you cannot read more values from that same iterator. Make a new one if you need the values again.

Remember
iterator.every(callback)

callback returns truthy for all → true
callback returns falsy once  → false (stops early)
empty iterator             → true

Consumes the iterator (it is closed after the call).
Callback gets (value, index).

Syntax

Call it on an iterator and pass a function that returns true or false for each value.

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

const allPositive = nums.every((n) => n > 0);
console.log(allPositive);   // true
CallWhat it does
iterator.every(callback)Return true if every value passes the test; otherwise false.
[1, 2, 3].values().every(fn)Get an iterator from an array, then test every value.
[].values().every(fn)An empty iterator returns true (nothing failed the test).
callback(value, index)Your function receives the current value and its zero-based index.

A standard JavaScript method (Iterator helpers, Baseline 2025) on every iterator, from Iterator.prototype. No import required. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), filter(), find(), flatMap(), forEach(), includes(), join(), map(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Iterator helpers (Baseline 2025)
Iterator.prototype.every(callbackFn)

// callbackFn : (value, index) => boolean-like
// returns    : true or false

Parameters

ParameterDescription
callbackFnRequired. A function called for each value. Return a truthy value to say "this one passes", or a falsy value to say "this one fails". It receives value (the current item) and index (starting at 0).

Return Value

Return ValueDescription
booleantrue if every value passed the test, or if the iterator was empty. false as soon as one value fails. The iterator is closed either way.

JavaScript Examples

Example 1 — Check That Every Value Passes

Test whether every number from an iterator is greater than zero.

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const allPositive = nums.every((n) => n > 0);

console.log("All positive: " + allPositive);
Try It Yourself

The Try It page first checks that iterator.every() 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 one by one.
  2. Test every value. The callback (n) => n > 0 returns true for 1, 2, 3, 4, and 5.
  3. Read the result. Because nothing failed, every() returns true.

Example 2 — Stop When One Value Fails

See that every() returns false as soon as one value does not pass the test.

JavaScript
const nums = [2, 4, 5, 8].values();
const allEven = nums.every((n) => n % 2 === 0);

console.log("All even: " + allEven);
Try It Yourself

The Try It page first checks that iterator.every() 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. Start checking. 2 and 4 are even, so they pass.
  2. Hit a failure. 5 is odd, so the callback returns falsy and every() stops.
  3. Result is false. The later value 8 is never tested, and the iterator is closed.

Example 3 — See That the Iterator Is Used Up

After every() runs, calling next() on the same iterator shows it is already done.

JavaScript
const nums = [1, 2, 3].values();
const ok = nums.every((n) => n < 10);
const after = nums.next();

console.log("every result: " + ok);
console.log("done after: " + after.done);
Try It Yourself

The Try It page first checks that iterator.every() 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. Run every(). All three values are less than 10, so the result is true.
  2. Iterator finished. Because every value was read, the iterator has nothing left.
  3. Check next(). after.done is true, so there are no values left to read.

Browser & Runtime Support

Iterator.prototype.every() is an Iterator helper (Baseline Newly available since March 2025). It works in current browsers and in Node.js 22 or newer.

✓ Baseline 2025 · Newly available

iterator.every()

Supported in Chrome 122+, Edge 122+, Firefox 131+, Safari 18.4+, Opera 108+ and Node.js 22+. Internet Explorer never got it.

2025 Standard since
Google Chrome 122+ · Desktop & Mobile
Full support
Microsoft Edge 122+ · Chromium based
Full support
Mozilla Firefox 131+ · Desktop & Mobile
Full support
Apple Safari 18.4+ · macOS & iOS
Full support
Opera 108+ · Chromium based
Full support
Samsung Internet 26+ · Android
Supported
Android WebView 122+ · Chromium based
Supported
Node.js 22+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
iterator.every() Current browsers

Bottom line: Check support with a typeof test before you use it in older browsers. Prefer chaining helpers and calling toArray() last.

Frequently Asked Questions

It tests each value from an iterator with your callback. If every value passes, it returns true. If one fails, it returns false and stops. The iterator is consumed either way.
Yes. An empty iterator returns true, because there was no value that failed the test. The same idea exists for Array.prototype.every().
No. every() closes the iterator. Create a new one (for example call .values() again) if you need the values once more.
Two: the current value and its zero-based index. Return any truthy value to pass, or any falsy value to fail.
The idea is the same, but it runs on an iterator instead of an array. It is part of the Iterator helpers, so check support in older browsers with a typeof test.

Next: filter()

Learn how to keep only the values that pass a test, and chain more iterator helpers afterward.

filter() 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