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()returnstrueif at least one element satisfies the condition, otherwisefalse.- 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
const numbers = [1, 3, 5, 6, 7];
const hasEven = numbers.some(num => num % 2 === 0);
console.log(hasEven); // truesome() returned true because the array contains at least one even number (6), and iteration stopped there.
Syntax and parameters
const result = array.some((element, index, array) => {
return condition;
});Callback parameters:
| Argument | Description |
|---|---|
element | the current array element |
index | the index of the current element |
array | the 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.
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); // trueChecking that a value is present.
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); // falseAn empty array. There are no elements, so none of them can satisfy the condition.
console.log([].some(x => x > 0)); // falseA plain numeric illustration.
const arr = [1, 2, 3, 4, 5];
console.log(arr.some(x => x > 3)); // true
console.log(arr.some(x => x < 0)); // falseThe 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.
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 adultThe 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
| Goal | Is some() a good fit |
|---|---|
| Check that at least one element matches a condition | Yes |
| Check that every element matches a condition | No, use every() |
| Get the element itself | No, use find() |
| Get the list of all matching elements | No, use filter() |
A comparison with similar methods:
| Method | What it returns | Condition | Does it stop at the first match |
|---|---|---|---|
some() | true / false | at least one element matches | yes |
every() | true / false | all elements match | yes, on the first false |
find() | the element or undefined | at least one element matches | yes |
filter() | a new array | all matching elements | no |
A formula worth memorising: arr.some(condition) gives true or false.
Common mistakes
1. Expecting an array instead of a boolean.
const result = arr.some(x => x > 10);
console.log(result.length); // TypeError, some() returns true or false2. A missing return in a callback with curly braces. The function returns undefined, which is falsy, so the result is always false.
arr.some(num => { num > 5 }); // always falseThe fix:
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 readyA concise answer to help you respond confidently on this topic during an interview.