The Some Method: Testing Any Element
You'll learn how Array.some() checks if at least one element in an array satisfies a condition, stopping as soon as it finds a match.
What Is Array.some()?
While every() requires all elements to pass a test, some() only needs one element to pass. Think of it like checking if there's any milk left in the fridge—you don't need to verify every shelf, just find one carton.
The some() method takes a predicate function (a test) and returns true if at least one element passes that test, or false if none do.
How It Works
const numbers = [1, 3, 5, 8, 9];
const hasEven = numbers.some(num => num % 2 === 0);
console.log(hasEven); // true (because 8 is even)
const allOdd = [1, 3, 5, 9];
const anyEven = allOdd.some(num => num % 2 === 0);
console.log(anyEven); // false (no even numbers)
Like every(), some() also short-circuits. Once it finds an element that passes the test, it immediately returns true without checking the rest:
const scores = [45, 82, 91, 67];
const hasPassingGrade = scores.some(score => score >= 60);
// Stops at 82, doesn't check 91 or 67
Practical Example
const users = [
{ name: 'Alice', admin: false },
{ name: 'Bob', admin: true },
{ name: 'Carol', admin: false }
];
const hasAdmin = users.some(user => user.admin);
console.log(hasAdmin); // true
Key Takeaway: Use Array.some() to check if any element meets a condition—it returns true on the first match and stops immediately, making it efficient for existence checks.