Skip to main content

Array some() method

some() is a logical array method that checks whether at least one element satisfies a condition and returns true or false. As soon as the first matching element is found the loop stops, so the method behaves as a fast existence check rather than a full scan.

Theory

TL;DR

  • some() returns true if at least one element satisfies the condition, otherwise false.
  • Iteration stops at the first match, the remaining elements are never checked.
  • For an empty array the result is always false.
  • The callback must return a value, otherwise the condition is always falsy.
  • some() means "at least one", every() means "all", find() returns the element itself, filter() returns an array.

Quick example

javascript
const numbers = [1, 3, 5, 6, 7]; const hasEven = numbers.some(num => num % 2 === 0); console.log(hasEven); // true

some() returned true because the array contains at least one even number (6), and iteration stopped there.

Syntax and parameters

javascript
const result = array.some((element, index, array) => { return condition; });

Callback parameters:

ArgumentDescription
elementthe current array element
indexthe index of the current element
arraythe source array itself

Typical use cases

Checking whether there are any adult users. The method stops as soon as it finds the first adult user.

javascript
const users = [ { name: 'Tim', age: 17 }, { name: 'Alex', age: 21 }, { name: 'John', age: 16 } ]; const hasAdult = users.some(user => user.age >= 18); console.log(hasAdult); // true

Checking that a value is present.

javascript
const fruits = ['apple', 'banana', 'cherry']; const hasBanana = fruits.some(fruit => fruit === 'banana'); console.log(hasBanana); // true const hasMango = fruits.some(fruit => fruit === 'mango'); console.log(hasMango); // false

An empty array. There are no elements, so none of them can satisfy the condition.

javascript
console.log([].some(x => x > 0)); // false

A plain numeric illustration.

javascript
const arr = [1, 2, 3, 4, 5]; console.log(arr.some(x => x > 3)); // true console.log(arr.some(x => x < 0)); // false

The difference between some() and every()

some() answers the question "is there at least one", while every() answers "are they all". Both bail out early: some() on the first true, every() on the first false.

javascript
const ages = [18, 22, 30, 16]; console.log(ages.some(age => age < 18)); // true, there is at least one minor console.log(ages.every(age => age >= 18)); // false, not everyone is an adult

The edge case is worth remembering too: on an empty array some() gives false while every() gives true.

When to use some() and when to use other methods

GoalIs some() a good fit
Check that at least one element matches a conditionYes
Check that every element matches a conditionNo, use every()
Get the element itselfNo, use find()
Get the list of all matching elementsNo, use filter()

A comparison with similar methods:

MethodWhat it returnsConditionDoes it stop at the first match
some()true / falseat least one element matchesyes
every()true / falseall elements matchyes, on the first false
find()the element or undefinedat least one element matchesyes
filter()a new arrayall matching elementsno

A formula worth memorising: arr.some(condition) gives true or false.

Common mistakes

1. Expecting an array instead of a boolean.

javascript
const result = arr.some(x => x > 10); console.log(result.length); // TypeError, some() returns true or false

2. A missing return in a callback with curly braces. The function returns undefined, which is falsy, so the result is always false.

javascript
arr.some(num => { num > 5 }); // always false

The fix:

javascript
arr.some(num => num > 5); // or arr.some(num => { return num > 5 });

3. Confusing some() with every(). some() means at least one element passes the condition, every() means all elements pass it. Swapping one for the other silently changes the logic of the check.

4. Using some() for side effects. The method is meant for checking, not for iterating with actions; use forEach() or a plain for...of for that.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.