Array.find(), Array.some(), and Array.every() in JavaScript

Hero image for Array.find(), Array.some(), and Array.every() in JavaScript. Image by drmakete lab.
Hero image for 'Array.find(), Array.some(), and Array.every() in JavaScript.' Image by drmakete lab.

JavaScript arrays have several methods that look similar at first because they all involve asking questions about items. The confusion usually starts when developers know one of them well enough to guess at the others and then get the wrong kind of result back.

find(), some(), and every() are a good example of that.

They all loop through an array with a test function, but they answer different questions:

  • find() asks, "which item matches?"
  • some() asks, "does at least one item match?"
  • every() asks, "do all items match?"

Once you frame them that way, the differences become much easier to remember.


find() returns the first matching item

Use find() when you want the actual item that matches a condition.

const users = [  { id: 1, name: 'Ellie' },  { id: 2, name: 'Maddie' },  { id: 3, name: 'Sophie' },];const user = users.find((entry) => {  return entry.id === 2;});

Here, user becomes:

{ id: 2, name: 'Maddie' }

If nothing matches, find() returns undefined.

That return type is important because it shapes how you handle the result.


some() returns a boolean

Use some() when you only care whether at least one item passes the test.

const hasEditors = users.some((entry) => {  return entry.name === 'Ellie';});

The result here is true or false.

That makes some() a very clean choice for checks such as:

  • does the cart contain a discounted item?
  • is any field invalid?
  • has any result matched the query?

If you do not need the matching item itself, some() often expresses the intent more clearly than find().


every() also returns a boolean, but asks the opposite question

every() checks whether all items match the condition.

const allHaveNames = users.every((entry) => {  return entry.name.trim() !== '';});

Again, the result is a boolean.

This makes every() useful for:

  • validating that all required values are present
  • checking whether every item in a list meets a rule
  • confirming a collection is in a safe or expected state

It is basically the stricter sibling of some().


The Return Values are the Main Thing to Remember

This is the simplest comparison:

  • find() returns an item or undefined
  • some() returns true or false
  • every() returns true or false

If you remember that clearly, a lot of confusion disappears.

For example, if you write:

const hasMatch = users.find((entry) => {  return entry.id === 2;});

then hasMatch is not a boolean. It is the matching object or undefined.

That can still be used in a truthy check, but it is not the same semantic shape as some().


A Practical Example: Form Validation

Imagine an array of field states:

const fields = [  { name: 'email', valid: true },  { name: 'postcode', valid: true },  { name: 'phone', valid: false },];

If you want the first invalid field:

const firstInvalidField = fields.find((field) => {  return !field.valid;});

If you only want to know whether any field is invalid:

const hasInvalidField = fields.some((field) => {  return !field.valid;});

If you want to check whether all fields are valid:

const allFieldsValid = fields.every((field) => {  return field.valid;});

Same data, same style of callback, three different questions.


find() stops early, and so do some() and every()

All three methods stop as soon as they have enough information to return.

That means:

  • find() stops at the first match
  • some() stops at the first truthy match
  • every() stops at the first failing item

This is useful both for performance and for intent. These methods are not asking you to inspect the whole array if the answer becomes clear earlier.


Empty arrays can trip people up with every()

This is a small but important detail.

If you call every() on an empty array, it returns true.

console.log([].every(() => false));  // true

That feels odd at first, but it follows the logic of the question: there are no items that break the rule.

This is one of those cases where the method is mathematically consistent but can still surprise a beginner. If emptiness has a special meaning in your application, account for that explicitly.


Choose the Method That Matches the Question

This is really the best rule.

Use find() when you need:

  • the matching item
  • or undefined if none exists

Use some() when you need:

  • a yes or no answer about at least one match

Use every() when you need:

  • a yes or no answer about all items matching

If you force one method to do the job of another, the code usually becomes less clear.


A quick comparison with filter()

People sometimes reach for filter() here as well.

That can be fine, but filter() returns all matching items as a new array. If you only need one item, one boolean, or one allitems check, these three methods often express the intent more directly.

For example, using filter() to answer "is there at least one invalid item?" is usually less direct than just using some().


Wrapping up

find(), some(), and every() all use a callback to test array items, but they are solving different problems. find() returns the first matching item, some() tells you whether at least one item matches, and every() tells you whether they all do. Once you match the method to the actual question, these become some of the clearest array tools in JavaScript.

Key Takeaways

  • find() returns the first matching item or undefined.
  • some() returns true if at least one item matches.
  • every() returns true only if all items match.
  • All three stop early once the answer is clear.
  • The easiest way to choose between them is to ask whether you need an item, anymatch boolean, or allmatch boolean.

When the method matches the question properly, array code gets much easier to read and much less errorprone.


Categories:

  1. Development
  2. Front‑End Development
  3. Guides
  4. JavaScript