JS Array Some and Every Methods: Complete Guide
some() checks if any element passes a test. every() checks if all elements pass. Learn how these boolean array methods work with clear examples and practical use cases.
some() and every() are array methods that answer boolean questions about an array. They do not return a new array like map() or a single accumulated value like reduce(). They return true or false.
- some() asks: "Does at least one element satisfy the condition?"
- every() asks: "Do all elements satisfy the condition?"
Both take a callback function that returns true or false for each element. Both stop early as soon as the answer is determined, which keeps them efficient even on arrays with thousands of items.
some() -- At Least One Passes
some() returns true if the callback returns true for any element. It stops iterating as soon as it finds a match.
const scores = [45, 72, 88, 39, 95];
const hasPassingScore = scores.some(score => score >= 60);
console.log(hasPassingScore); // true (72, 88, and 95 are >= 60)scores.some() checks each element until it hits 72. Since 72 >= 60 is true, it immediately returns true and never checks 88, 39, or 95. This short-circuit behavior makes some() efficient on large arrays.
const temperatures = [15, 18, 22, 19, 16];
const isFreezing = temperatures.some(temp => temp <= 0);
console.log(isFreezing); // false (every temperature is above 0)When no element passes, some() returns false.
Practical some() Use Cases
Check if a user has any admin roles. Calling some() on a list of role strings is a quick way to gate access without writing a manual loop:
const userRoles = ["editor", "viewer"];
const isAdmin = userRoles.some(role => role === "admin");
if (!isAdmin) {
console.log("Access restricted.");
}Find if an array contains a specific value. A callback with a strict equality check turns some() into a search for one matching item:
const fruits = ["apple", "banana", "orange"];
const hasBanana = fruits.some(fruit => fruit === "banana");
console.log(hasBanana); // trueFor simple equality checks like this, includes() is a good alternative: fruits.includes("banana"). Use some() when you need a more complex condition than strict equality.
Check if any item is on sale. The condition here reads a boolean property directly off each object instead of comparing it to a fixed value, which is exactly the kind of check some() handles better than includes():
const products = [
{ name: "Laptop", price: 999, onSale: false },
{ name: "Mouse", price: 29, onSale: true },
{ name: "Keyboard", price: 79, onSale: false }
];
const hasSaleItem = products.some(product => product.onSale);
console.log(hasSaleItem); // trueevery() -- All Must Pass
every() returns true only if the callback returns true for every element. It stops as soon as it finds an element that fails.
const scores = [85, 92, 78, 95, 88];
const allPassing = scores.every(score => score >= 60);
console.log(allPassing); // true (all scores are >= 60)If a single element fails, every() returns false immediately without checking the rest of the array, which is useful for validating a batch of values against a rule:
const passwords = ["Str0ng!", "W3ak", "Secur3#"];
const allStrong = passwords.every(pw => pw.length >= 8);
console.log(allStrong); // false ("W3ak" has only 4 characters)every() stops at "W3ak" and never checks "Secur3#".
Practical every() Use Cases
Validate all form fields are filled. Checking that every field has a non-empty value before submitting is a classic use for every():
const fields = [
{ name: "email", value: "user@example.com" },
{ name: "password", value: "" },
{ name: "username", value: "alice123" }
];
const allFilled = fields.every(field => field.value !== "");
if (!allFilled) {
console.log("Please fill in all fields.");
}Check if all users are verified. The same pattern works for any boolean flag on a list of objects, not just form validation:
const users = [
{ name: "Alice", verified: true },
{ name: "Bob", verified: true },
{ name: "Carol", verified: false }
];
const allVerified = users.every(user => user.verified);
console.log(allVerified); // falseShort-Circuit Behavior Visualized
some() keeps going as long as the callback returns false and stops at the first true. every() keeps going as long as the callback returns true and stops at the first false.
This means you do not need to worry about performance when checking large arrays -- both methods do the minimum work needed to determine the answer.
Comparison: some() vs every() vs includes()
| Method | Question | Returns | Short-circuits |
|---|---|---|---|
some(fn) | Any element passes? | true / false | On first true |
every(fn) | All elements pass? | true / false | On first false |
includes(val) | Array contains value? | true / false | On match |
includes() is the simplest of the three. Use it when you only need to check if a specific value exists.
Use some() when your condition involves more than equality, like checking a property of an object or a range. Use every() when all elements must meet a standard.
Common Mistakes
Expecting some() to return the matching element. It only tells you whether a match exists, not what that match is:
const users = [{ name: "Alice" }, { name: "Bob" }];
// Wrong: some returns true/false, not the element
const user = users.some(u => u.name === "Bob");
console.log(user); // true, not { name: "Bob" }
// Right: use find() to get the actual element
const bob = users.find(u => u.name === "Bob");
console.log(bob); // { name: "Bob" }some() tells you whether an element exists. find() gives you the element itself. For the find() method, see JavaScript Array Find and findIndex Methods Guide.
Forgetting that every() returns true on an empty array. This is mathematically valid but can slip past validation logic unnoticed:
const empty = [];
console.log(empty.every(item => item > 100)); // true (vacuously)
// Guard against this if needed
if (empty.length > 0 && empty.every(item => item > 100)) {
console.log("All items > 100");
}This is mathematically correct but can cause logic bugs. If an empty array should not pass validation, check the length first.
Confusing some() with every() in negative checks. Reading the question in plain English first makes it easier to pick the right method:
const items = ["apple", "banana", ""];
// "Are all items non-empty?" -- use every()
const allValid = items.every(item => item !== "");
console.log(allValid); // false (the empty string fails)
// "Is there any empty item?" -- use some()
const hasEmpty = items.some(item => item === "");
console.log(hasEmpty); // trueFor more array testing methods, see filter to extract matching elements instead of just testing them.
Rune AI
Key Insights
- some() returns true if at least one element passes the test callback.
- every() returns true only if all elements pass the test callback.
- Both methods short-circuit: some stops at the first true, every stops at the first false.
- Use some() for 'at least one' checks, like finding if a list contains any active item.
- Use every() for 'all must pass' checks, like form field validation.
Frequently Asked Questions
Do some() and every() always check every element?
What does every() return on an empty array?
What does some() return on an empty array?
Conclusion
some() and every() turn array testing from manual loops into readable one-liners. Use some() to ask 'does any element match?' and every() to ask 'do all elements match?' Their short-circuit behavior keeps them efficient, and their boolean return values make them perfect for conditional logic, form validation, and permission checks.
More in this topic
JavaScript While Loop Explained: A Complete Guide
A while loop repeats code as long as a condition stays true. Learn the syntax, see practical examples, and understand when a while loop is the right choice over a for loop.
JavaScript Loops Tutorial: for, while, do while
Loops let JavaScript repeat code without writing it twice. Learn the three core loop types, what each one does, and when to choose one over another.
How to Loop Through Arrays Using JS for Loops Guide
Looping through arrays is the most practical use of JavaScript for loops. Learn how to access each element by index, avoid off-by-one errors, and choose between for, for...of, and forEach.