(If you know C# LINQ , it's like Any vs All)

  • some will return true if any predicate is true

  • every will return true if all predicate is true

Where predicate means function that returns bool ( true/false) for each element

every returns on first false.
some returns on first true

Answer from Royi Namir on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › some
Array.prototype.some() - JavaScript | MDN
1 week ago - The some() method of Array instances returns true if it finds an element in the array that satisfies the provided testing function. Otherwise, it returns false.
🌐
Medium
medium.com › coding-in-depth › when-to-use-every-some-any-foreach-and-map-in-javascript-9ed598010946
When to use every(), some(), any(), forEach() and map() in JavaScript | by Coding In depth | Coding In Depth | Medium
August 8, 2020 - Is Array.any() exist in the JavaScript? The answer is no. However, Array.some() do the purpose of getting any elements. The method Some will return true when the first matching condition will be met.
Discussions

What is the correct situation to use array.find() vs. array.includes vs. array.some() ?
const value = arr.find(test) — return the value that passes your test function for when you need to run a test to determine which value you want const bool = arr.some(test) — return true if at least one element passes your test for when you need to see if anything in your array passes your test function const bool = arr.includes(value) — check if a value exists in an array for when you already know the value and you want to check if the array has a copy More on reddit.com
🌐 r/learnjavascript
7
25
September 14, 2019
Enumerable#any vs Array#some
In the docs, it says Enumerable#any should return a boolean, but this isn't necessarily true. It returns the first truthy value returned or the last falsey value returned. This is inconsistent with Array#some as well, which always return... More on github.com
🌐 github.com
9
August 8, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-the-difference-between-every-and-some-methods-in-javascript
What is the difference between every() and some() methods in JavaScript ? - GeeksforGeeks
July 12, 2025 - The Array.some() method in JavaScript ... The only difference is that the some() method will return true if any predicate is true while every() method will return true if all predicates are true....
🌐
W3Schools
w3schools.com › jsref › jsref_some.asp
W3Schools.com
The some() method executes the callback function once for each array element. The some() method returns true (and stops) if the function returns true for one of the array elements.
🌐
Reddit
reddit.com › r/learnjavascript › what is the correct situation to use array.find() vs. array.includes vs. array.some() ?
What is the correct situation to use array.find() vs. ...
September 14, 2019 -

I understand how each of these methods work, but they all seem to have similar functions to one another, and I'm not sure as to what situation might call for what method.

Top answer
1 of 2
10

If I understand your point correctly, you seem to be mis-using or abusing every and some but it's a little unavoidable if you want to change the elements of your arrays directly. Correct me if I'm wrong, but what you're trying to do is find out if some or every element in your sequence exhibits a certain condition then modify those elements. Also, your code seems to be applying something to all items until you find one that doesn't pass the predicate and I don't think that's what you mean to be doing. Anyways.

Let's take your first example (slightly modified)

if (input.every(function (that) {
    return typeof that === "number";
})) {
    input.every(function (that) {
        that.foo();
    }
} else {
    return;
}

What you're doing here actually goes a little against the spirit of the some/every/map/reduce/filter/etc concepts. Every isn't meant to be used to affect every item that conforms to something, rather it should only be used to tell you if every item in a collection does. If you want to apply a function to all items for which a predicate evaluates to true, the "good" way to do it is

var filtered = array.filter(function(item) {
    return typeof item === "number";
});

var mapped = filtered.map(function(item) {
    return item.foo(); //provided foo() has no side effects and returns a new object of item's type instead.  See note about foreach below.
});

Alternatively, you could use foreach instead of map to modify the items in-place.

The same logic applies to some, basically:

  • You use every to test if all elements in an array pass some test.
  • You use some to test if at least one element in an array passes some test.
  • You use map to return a new array containing 1 element (which is the result of a function of your choice) for every element in an input array.
  • You use filter to return an array of length 0 < length < initial array length elements, all contained in the original array and all passing the supplied predicate test.
  • You use foreach if you want map but in-place
  • You use reduce if you want to combine the results of an array in a single object result (which could be an array but doesn't have to).

The more you use them (and the more you write LISP code), the more you realize how they are related and how it's even possible to emulate/implement one with the others. What's powerful with these queries and what's really interesting is their semantics, and how they really push you towards eliminating harmful side-effects in your code.

EDIT (in light of comments): So let's say you want to validate that every element is an object and convert them to an Application Model if they're all valid. One way to do this in a single pass would be:

var dirty = false;
var app_domain_objects = input.map(function(item) {
    if(validate(item)) {
        return new Model(item);
    } else {
        dirty = true; //dirty is captured by the function passed to map, but you know that :)
    }
});
if(dirty) {
    //your validation test failed, do w/e you need to
} else {
    //You can use app_domain_objects
}

This way, when an object doesn't pass validation, you still keep iterating through the entire array, which would be slower than just validating with every. However, most of the time your array will be valid (or I should hope so), so in most cases you'll perform a single pass over your array and end up with a usable array of Application Model objects. Semantics will be respected, side-effects avoided and everyone will be happy!

Note that you could also write your own query, similar to foreach, which would apply a function to all members of an array and returns true/false if they all pass a predicate test. Something like:

function apply_to_every(arr, predicate, func) {
    var passed = true;
    for(var i = 0; i < array.length; ++i) {
        if(predicate(arr[i])) {
            func(arr[i]);
        } else {
            passed = false;
            break;
        }
    }
    return passed;
}

Although that would modify the array in place.

I hope this helps, it was very fun to write. Cheers!

2 of 2
-1

The side effects are not in the if condition, they are in the if's body. You have only determined whether or not to execute that body in the actual condition. There is nothing wrong with your approach here.

🌐
DEV Community
dev.to › amirfakour › understanding-some-and-every-array-methods-in-javascript-59fh
Understanding "some" and "every" Array Methods in Javascript - DEV Community
June 12, 2023 - In this example, the some method returns true because the number 12 is greater than 10. The Array.every() method tests if all elements in an array pass the provided test function.
Find elsewhere
🌐
Go Make Things
gomakethings.com › why-would-you-use-array.some-or-array.every-over-array.filter
Why would you use Array.some() or Array.every() over Array.filter() | Go Make Things
Array.every() returns true if all items in your array matches some criteria you specify as part of a callback function. Array.filter() returns a new array of items, removing any from the original array that don’t match some criteria you specify as part of a callback function.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
The function fn is called on each element of the array similar to map. If any/all results are true, returns true, otherwise false. These methods behave sort of like || and && operators: if fn returns a truthy value, arr.some() immediately returns true and stops iterating over the rest of items; if fn returns a falsy value, arr.every() immediately returns false and stops iterating over the rest of items as well.
🌐
GitHub
github.com › emberjs › ember.js › issues › 12533
Enumerable#any vs Array#some · Issue #12533 · emberjs/ember.js
August 8, 2015 - In the docs, it says Enumerable#any should return a boolean, but this isn't necessarily true. It returns the first truthy value returned or the last falsey value returned. This is inconsistent with Array#some as well, which always returns true or false.
Published   Oct 29, 2015
🌐
LinkedIn
linkedin.com › pulse › understanding-distinction-arraysome-vs-arrayfind-shuaibu-muhammad-20j9f
Understanding the Distinction: Array.some() vs. Array.find() ...
February 26, 2024 - Suppose you have an array of numbers and want to determine if any of them are even. You can use Array.some() to quickly check for the existence of at least one even number without iterating through the entire array.
🌐
Refine
refine.dev › home › blog › tutorials › a definitive guide on javascript every method
A Definitive guide on JavaScript every Method | Refine
January 17, 2025 - This is so because "all items" in an empty array vacuously satisfy the condition that they are even or anything else. Supposedly. In JavaScript, some() returns true if any array element meets a condition, while every() checks if all elements do.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › every
Array.prototype.every() - JavaScript | MDN
1 week ago - The every() method of Array instances returns false if it finds an element in the array that does not satisfy the provided testing function. Otherwise, it returns true.
🌐
Educative
educative.io › answers › what-are-the-every-and-some-methods-in-javascript
What are the every() and some() methods in JavaScript?
We stored the value the arr.some() returns in a variable, called boolVal, and then console.log(boolVal), which returned true. Unlike the some() method, every() checks that every element in the given array pass the test within the callback function.
🌐
GitConnected
levelup.gitconnected.com › javascript-array-some-vs-every-vs-foreach-knowledge-scoops-81dfe43369c6
JavaScript Arrays: Some(), Every(), and forEach() | by Kunal Tandon | Level Up Coding
December 2, 2019 - As all of the values in the array arr are positive, the boolean expression satisfies for all of the values. We receive true as output. If there is a single value that doesn’t satisfy the boolean expression, we get the boolean output false. ... The every() method stops iterating over the elements as soon as any value fails the boolean expression.
🌐
freeCodeCamp
freecodecamp.org › news › learn-the-every-and-some-array-methods-in-javascript
JavaScript Array Methods – How to Use every() and some() in JS
August 10, 2022 - Now let's use some to test if some number in the array is odd: ... That's really true! 91 is odd. But this is not the end of the story. These methods have some more depth. Let's dig in. The way to use every and some array methods is exactly the same. They have the same set of parameters and those parameters also mean identical things.
🌐
DEV Community
dev.to › nas5w › learn-the-javascript-array-every-and-array-some-methods-356c
Learn the JavaScript Array.every() and Array.some() Methods - DEV Community
June 9, 2020 - Array.every takes a callback function as an argument. If the function returns true for each item in the array, Array.every returns true. Let's check it out. function test(el) { return el < 10; } [1, 2, 3, 4, 5, 6].every(test); // true · Since every item in the array is less than 10, the Array.every method returns true.
🌐
Linux Hint
linuxhint.com › difference-between-every-and-some-methods-javascript
Difference between every() and some() methods in ...
June 4, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
The type names String, Number, and Boolean (starting with capital letters) are legal, but refer to some special built-in types that will very rarely appear in your code. Always use string, number, or boolean for types. To specify the type of an array like [1, 2, 3], you can use the syntax number[]; this syntax works for any type (e.g.