JavaScript Array every() Method

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

What You’ll Learn

The every() method checks whether all elements in an array satisfy a condition you define in a callback. It returns a boolean and stops as soon as one element fails. This tutorial covers syntax, five examples, empty-array behavior, and how it compares to some() and filter().

01

Syntax

every(cb)

02

All pass?

true / false

03

Callback

Test function

04

Short-circuit

Stops early

05

Empty []

Returns true

06

ES5

Universal

Introduction

When validating data, you often need a single yes/no answer: do all items meet a rule? The every() method is built for that question. Pass a test function; if every element passes, you get true.

Unlike filter(), which returns matching elements, or map(), which transforms them, every() only tells you whether the whole array satisfies your condition.

Understanding the every() Method

array.every(callback) walks the array from index 0 upward. For each element it calls your callback with (element, index, array). If the callback returns a falsy value for any element, every() immediately returns false without checking the rest.

If every callback returns a truthy value, the final result is true.

💡
Beginner Tip

Think of every() as a strict gatekeeper: one failure blocks the whole array. Its partner some() is the opposite—one success is enough.

📝 Syntax

General form of Array.prototype.every:

JavaScript
array.every(callback(element, index, array), thisArg)

Parameters

  • callback — function invoked per element. Should return a boolean (or truthy/falsy).
  • element — current array item.
  • index — optional; position of the element.
  • array — optional; the array being traversed.
  • thisArg — optional; value to use as this inside the callback.

Return value

  • true if the callback is truthy for every element (including empty arrays).
  • false as soon as any element fails the test.
  • The original array is not modified by every() itself.

Common patterns

  • nums.every(n => n > 0) — all positive?
  • users.every(u => u.active) — all active accounts?
  • fields.every(f => f.trim() !== "") — no empty form fields?

⚡ Quick Reference

GoalCode
Test all elementsarr.every(callback)
All even numbers?arr.every(n => n % 2 === 0)
Empty array resulttrue (vacuous truth)
Stops on first fail?Yes
Return typeBoolean

📋 every() vs some() vs filter() vs find()

All accept a callback, but they answer different questions and return different types.

every
all pass?

Returns boolean

some
any pass?

Opposite logic

filter
keep matches

Returns new array

find
first match

Returns element

Examples Gallery

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

📚 Getting Started

Basic boolean tests on numeric arrays.

Example 1 — Check If All Numbers Are Even

Return true only when every element passes the modulo test.

JavaScript
const numbers = [2, 4, 6, 8, 10];

const allEven = numbers.every((num) => num % 2 === 0);

console.log(allEven);
// true
Try It Yourself

How It Works

Each number divides evenly by 2, so every callback returns true and every() finishes with true.

Example 2 — Return false When One Element Fails

As soon as a value does not meet the rule, every() stops and returns false.

JavaScript
const numbers = [2, 4, 6, 8, 10];

const allGreaterThanTen = numbers.every((num) => num > 10);

console.log(allGreaterThanTen);
// false
Try It Yourself

How It Works

The first element 2 is not greater than 10. The callback returns false, so remaining elements are never tested.

📈 Practical Patterns

Edge cases and real-world validation.

Example 3 — Empty Arrays Always Return true

This surprises beginners but follows logical “vacuous truth”: zero elements means zero failures.

JavaScript
const empty = [];

const result = empty.every((n) => n > 0);

console.log(result);
// true
Try It Yourself

How It Works

When length is 0, the callback never runs and every() returns true. Guard with arr.length > 0 if an empty list should fail your business rule.

Example 4 — Validate a Property on Every Object

Check that all records in an array share a condition on one field.

JavaScript
const students = [
  { name: "Alice", age: 22 },
  { name: "Bob", age: 25 },
  { name: "Charlie", age: 20 }
];

const allAdults = students.every((student) => student.age >= 18);

console.log(allAdults);
// true
Try It Yourself

How It Works

The callback reads student.age for each object. Every age is 18 or higher, so the result is true.

Example 5 — Validate Form Fields Are Non-Empty

Ensure every string in an input array has content after trimming whitespace.

JavaScript
const fields = ["John", "Doe", "john.doe@example.com"];

const allFilled = fields.every((value) => value.trim() !== "");

console.log(allFilled);
// true

const incomplete = ["John", "  ", "john.doe@example.com"];
console.log(incomplete.every((v) => v.trim() !== ""));
// false
Try It Yourself

How It Works

Whitespace-only strings fail the trim check. This pattern is common before submitting forms or API payloads.

🚀 Common Use Cases

  • Form validation — confirm every required field is filled.
  • Permission checks — verify all users in a list have a role.
  • Data quality — ensure every record has required properties.
  • Numeric bounds — all scores above a passing threshold.
  • Type guards — every item is a string or number as expected.
  • Feature flags — all services report healthy status.

🧠 How every() Runs

1

Start at index 0

If length is 0, return true immediately.

Init
2

Call callback

Pass (element, index, array) for the current slot.

Test
3

Check result

Falsy callback result → return false and stop. Truthy → continue.

Decide
4

All passed

After the last element, return true. Array unchanged.

📝 Notes

  • Empty arrays return true by specification.
  • Skipped holes in sparse arrays are still visited; holes behave like undefined.
  • Return explicit booleans in callbacks for clarity, even though truthy/falsy works.
  • Do not mutate the array inside the callback in ways that change indexes you have not visited yet.
  • every() does not create a new array—use filter() when you need matches.
  • Available since ES5; excellent baseline compatibility.

Browser & Runtime Support

Array.prototype.every() has been part of JavaScript since ES5 (2009). It is one of the most widely supported array methods.

Baseline · ES5

Array.prototype.every()

Supported in Chrome 1+, Firefox 1.5+, Safari 3+, Edge 12+, IE 9+, and all modern Node.js versions.

99% Universal 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.every() Universal

Bottom line: Safe everywhere, including legacy environments. One of the safest array methods to adopt without polyfills.

Conclusion

The every() method gives you a clean boolean answer to “do all items satisfy this rule?” It short-circuits on failure, works on objects and primitives, and has been stable since ES5.

Pair it with some() when you need the opposite question, and remember the empty-array edge case when validating user input.

💡 Best Practices

✅ Do

  • Keep callbacks small and focused on one condition
  • Return explicit true / false
  • Guard empty arrays when your rule requires at least one item
  • Use every() for validation, filter() for collecting matches
  • Name results clearly: allValid, allAdults

❌ Don’t

  • Assume empty arrays should fail—they return true
  • Mutate the array unpredictably inside the callback
  • Use every() when you only need one match (some())
  • Rely on side effects in the callback—keep it pure
  • Forget sparse-array holes may fail tests unexpectedly

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.every()

Your foundation for all-or-nothing array tests.

5
Core concepts
02

All pass

Boolean result.

Logic
03

Short-circuit

Stops on fail.

Fast
📦 04

Empty []

Returns true.

Edge case
🔄 05

vs some()

Opposite test.

Compare

❓ Frequently Asked Questions

every() tests whether every element in an array passes a callback function. It returns true only if the callback returns a truthy value for every element; otherwise it returns false.
No. every() only reads elements through your callback. It does not change the array unless your callback does so deliberately (which is discouraged).
An empty array always returns true. This is vacuous truth: there are zero elements that fail the test.
Yes. every() short-circuits—it stops calling the callback as soon as one element returns a falsy value and immediately returns false.
every() asks 'do ALL pass?' and returns false on the first failure. some() asks 'does ANY pass?' and returns true on the first success. They are logical opposites for array testing.
every() has been available since ES5 (2009). It works in all modern browsers, Node.js, and even Internet Explorer 9+.
Did you know?

[].every(x => false) still returns true because the callback never runs. That is the same vacuous-truth idea as “all unicorns are pink” being considered true when there are zero unicorns to check.

Continue to fill()

Learn how to fill all or part of an array with a static value in place.

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