jsguides

Array.prototype.some()

some(callbackFn)

some() tests whether at least one element in the array passes the test implemented by the callback you pass in. It returns true if it finds an element for which the callback returns true, otherwise false.

Syntax

some(callbackFn)
some(callbackFn, thisArg)

Parameters

ParameterTypeDefaultDescription
callbackFnfunctionFunction to test each element. Called with (element, index, array).
thisArganyundefinedValue to use as this when executing callbackFn.

The callback function should return a truthy value to indicate the element passes the test.

Examples

These examples move from a simple numeric check to working with objects, strings, and finally real-world patterns like form validation and permission checks. Each block builds on the behaviour shown in the previous one.

Basic usage

const numbers = [1, 2, 3, 4, 5];

// Check if any element is greater than 3
const hasLargeNumber = numbers.some(n => n > 3);
console.log(hasLargeNumber);
// true

// Check if any element is negative
const hasNegative = numbers.some(n => n < 0);
console.log(hasNegative);
// false

A numeric test is the most common starting point, but some() becomes far more useful when you check properties on objects. The callback can inspect any field, making it a good fit for records like user lists and product catalogs.

Finding the first matching element

const users = [
  { name: 'Alice', active: false },
  { name: 'Bob', active: true },
  { name: 'Charlie', active: false }
];

const hasActiveUser = users.some(user => user.active);
console.log(hasActiveUser);
// true

Object properties are one common use case; string methods are another. Because the callback can call any method on the element, you can test for prefixes, lengths, or regex matches without looping manually. The same approach works for any element type that exposes methods you can branch on.

Using with strings

const words = ['apple', 'banana', 'cherry', 'date'];

// Check if any word starts with 'c'
const hasCWord = words.some(word => word.startsWith('c'));
console.log(hasCWord);
// true

// Check if any word is longer than 10 characters
const hasLongWord = words.some(word => word.length > 10);
console.log(hasLongWord);
// false

Common Patterns

some() fits naturally into validation and permission-checking workflows. Because it short-circuits, it stops at the first problem—a useful property when you want to flag an issue without scanning the whole list. The next two examples show this pattern with real data structures.

Validating form data

const formFields = [
  { name: 'email', value: '', required: true },
  { name: 'username', value: 'john', required: true },
  { name: 'bio', value: 'Hello', required: false }
];

const hasEmptyRequired = formFields.some(field => 
  field.required && !field.value
);
console.log(hasEmptyRequired);
// true - email is empty but required

Form validation checks whether any required field is empty, but the same pattern applies to permission checks. The callback simply tests whether the current value appears in a list of allowed entries. Both use cases rely on the same yes/no decision: does at least one array member satisfy the predicate?

Checking permissions

const userRoles = ['guest', 'reader', 'contributor'];

// Define required permissions
const requiredPermissions = ['admin', 'editor', 'owner'];

// Check if user has any elevated permission
const hasElevatedRole = userRoles.some(role => 
  requiredPermissions.includes(role)
);
console.log(hasElevatedRole);
// false

The real benefit of some() over filter().length > 0 becomes clear with large arrays. The next example shows short-circuit evaluation in action: some() stops after finding the first match, which makes it dramatically faster when the match is near the beginning.

Early termination

// some() short-circuits - stops after finding first match
const largeArray = Array.from({ length: 1000000 }, (_, i) => i);

const start = performance.now();
const found = largeArray.some(n => n > 500);
const end = performance.now();

console.log(found);
// true
console.log('Stopped after finding match');
// Stops iterating at 501 - very efficient!

How some() works

some() iterates each element in order and calls the callback with three arguments: the current element, its index, and the array. If the callback returns a truthy value for any element, some() immediately returns true. If the callback never returns truthy after all elements are visited, some() returns false. The iteration order is always ascending index order.

Short-circuit evaluation

some() stops iterating the moment the callback returns a truthy value. This is called short-circuit evaluation and it means that for large arrays, some() can be much faster than filter().length > 0 when a match exists near the beginning — filter always scans the full array, while some stops early.

Return value on empty array

Calling some() on an empty array always returns false, regardless of the callback. There are no elements to test, so the condition “at least one element passes” is vacuously false.

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

some() vs every()

some(fn) returns true if at least one element passes. every(fn) returns true only if all elements pass. They are logical duals: arr.some(fn) is equivalent to !arr.every(x => !fn(x)), and vice versa. This dual relationship means you can express either check in terms of the other.

const nums = [1, 2, 3, 4, 5];
nums.some(n => n > 3);  // true — 4 and 5 pass
nums.every(n => n > 3); // false — 1, 2, 3 fail

The relationship between some() and every() is precise: one inherits from classical logic. When every element must satisfy a condition, every() is the natural choice; when only one needs to, some() is faster because it stops early. But for simple value checks on flat arrays, neither is needed — includes() covers that case with less ceremony and the same early-exit behaviour.

some() vs includes()

Use includes(value) for exact value checks — it is simpler and equally fast. Use some(fn) when the match condition involves a function, such as checking a property value or testing a range.

const roles = ['admin', 'user'];
roles.includes('admin');          // true — simple value check
roles.some(r => r.startsWith('a')); // true — pattern-based check

includes() is simpler but limited to exact matches. When you need to test a pattern, a range, or a nested property, some() with a callback is the right tool. Both short-circuit, so neither has a performance advantage for early matches.

When some() Is Useful

some() fits well when you need a yes-or-no answer and do not care which element matched. That makes it a good choice for validation, permission checks, and other “any match?” questions. Because it stops as soon as it finds a passing value, it can also be a better fit than building a filtered list just to check whether the list is empty.

It is also useful when the condition is more complex than a direct equality test. For example, you can check a property, compare a range, or combine several predicates in one callback. That keeps the decision logic close to the data it applies to and avoids extra passes over the array.

See Also