JavaScript lesson · 18 min

JavaScript find, some, and every

Search arrays and ask yes/no questions with find, some, and every.

Code runs locally in your browser

What you will practice

  • Use find to get one matching item.
  • Use some to check whether at least one item matches.
  • Use every to check whether all items match.

What this means

Array search methods help you ask questions about a list without writing a full loop every time.

`find` returns the first item that matches a condition. `some` returns true when at least one item matches. `every` returns true only when all items match.

These methods use callback functions, so they are also good practice for reading callback-based code.

If this is your first time seeing this

These methods answer different questions about a list.

`find` gives you an item. `some` and `every` give you true or false.

Mini glossary

find
Returns the first array item that matches a condition.
some
Returns true when at least one item matches.
every
Returns true only when all items match.

Example from everyday life

Imagine checking a row of labeled boxes. `find` opens boxes until it finds the one you need. `some` asks whether any box contains a fragile item. `every` asks whether all boxes are sealed.

How it works step by step

  1. The code creates a list of tools with names and readiness flags.
  2. `find` returns the first server-side tool.
  3. `some` checks whether at least one tool is not ready.
  4. `every` checks whether every tool has a name.

Where you will use this

  • A product list finds one item by id.
  • A dashboard checks whether any task failed.
  • A form checks whether every required field has a value.

Before you run the code

Use these methods when the question is about existence or one matching item.

If you need a new list of all matching items, use `filter` instead of `find`.

Common beginner mistakes

  • Using `find` when you need all matching items. Use `filter` for that.
  • Forgetting that `find` can return `undefined` when nothing matches.
  • Mixing up `some` and `every` because both return booleans.

Run in browser

Try the example

Console output
Run the code to see console output here.
Exercise checks0 of 2 checks passed.
WaitingFinds one matching item
WaitingAnswers a yes/no array question

Code runs locally in a temporary browser worker with a timeout. It is not sent to Lumio analytics or executed on the server.

Try changing this next

  • Change the server tool privacy to `browser` and see what happens.
  • Add another planned tool.
  • Make one tool name empty and check `All named`.