Array.some()
Checks if at least one element passes a test (returns true/false).
array.some(predicateFn, thisArg?)This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Checks if at least one element passes a test (returns true/false).
The some() method tests whether at least one element in the array passes the test implemented by the provided predicate function. It returns a Boolean value. A key performance advantage is its short-circuiting behavior: once a value is found that satisfies the predicate, the method immediately returns true and stops iterating over remaining elements. This makes it more efficient than filter() or forEach() for existence checks. On an empty array, some() always returns false regardless of the condition (vacuous truth only applies to the every() method). It does not mutate the original array, though the predicate function can. Note that for sparse arrays, the predicate is not invoked for deleted or unassigned indexes, which prevents unnecessary processing of 'holes' in the array structure.
Quick reference
Syntax
array.some(predicateFn, thisArg?)
Inputs
Parameters
See it in practice
Examples
Checking for Even Numbers
var numbers = [1, 3, 5, 8, 11];
var hasEven = numbers.some(function(num) {
return num % 2 === 0;
});true
The method iterates through the array and returns true as soon as it encounters the number 8, skipping the final element 11.
Validating User Permissions
var userRoles = ['guest', 'editor', 'subscriber'];
var canEdit = userRoles.some(function(role) {
return role === 'admin' || role === 'editor';
});true
Commonly used in authorization logic to check if a user possesses at least one required permission or role.
Checking for Existence in Object Arrays
var tasks = [
{ id: 1, completed: true },
{ id: 2, completed: false },
{ id: 3, completed: false }
];
var hasPendingTasks = tasks.some(function(task) {
return !task.completed;
});true
Used to detect if any object within a collection meets a specific state criteria.
Debug faster
Common Errors
LogicError
Cause: Assuming some() returns true for empty arrays when checking generic conditions.
Fix: Remember that some() always returns false for an empty array. If you need a different result for empty sets, check the array length explicitly first.
[].some(function(x) { return true; }); // returns falseLogicError
Cause: Forgetting the return statement inside the predicate function.
Fix: Always ensure the predicate returns a truthy value to signal a match. Without a return, the callback returns undefined, which is falsy.
var match = [1, 2, 3].some(function(x) { x === 2 }); // match is falseRuntime support
Compatibility
Source: MDN Web Docs
Common questions
Frequently Asked Questions
Checks if at least one element passes a test (returns true/false).
predicate: Returns true for a matching element. thisArg: Value used as 'this' inside predicate.
LogicError: Remember that some() always returns false for an empty array. If you need a different result for empty sets, check the array length explicitly first. LogicError: Always ensure the predicate returns a truthy value to signal a match. Without a return, the callback returns undefined, which is falsy.