Skip to main content

some() in an array

The some() method is one of the boolean array methods in JavaScript. It checks whether at least one element satisfies the condition, and returns true or false. As soon as the first matching element is found, the iteration stops.

Syntax

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

Callback parameters:

ArgumentDescription
elementThe current array element
indexThe index of the current element
arrayThe original array itself

Example 1. Checking if there are even numbers

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 has at least one even number (6).

Example 2. Checking if there are adult users

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

some() stops as soon as it finds the first adult user.

Example 3. Checking for the presence of a value

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

Example 4. Working with an empty array

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

For an empty array some() always returns false, because there are no elements.

Common errors

  1. Expecting an array instead of a boolean
javascript
const result = arr.some(x => x > 10); console.log(result.length); // TypeError - some() returns true/false
  1. A forgotten return
javascript
arr.some(num => { num > 5 }); // always false

Correct:

javascript
arr.some(num => num > 5); // or arr.some(num => { return num > 5 });
  1. Confusing it with every()
  • some() -> at least one element passes the condition
  • every() -> all elements pass the condition

When to use some()

GoalIs some() suitable
Check that at least one element matches the conditionYes
Check that all elements match the conditionNo - use every()
Find the element itselfNo - use find()
Get a list of matching elementsNo - use filter()

Briefly:

some() returns true if at least one array element satisfies the condition.

Formula to remember: arr.some(condition) -> true | false

Example for clarity

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

Comparison with similar methods

MethodReturnsConditionStops after the first match
some()true / falseAt least one element matchesYes
every()true / falseAll elements matchYes (on the first false)
find()Element or undefinedAt least one element matchesYes
filter()New arrayAll matching elementsNo

Example comparing some() and every()

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

Short Answer

Interview ready
Premium

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