some() & every() in JavaScript

From the JavaScript Array Methods cheat sheet · Searching & Testing · verified Jul 2026

some() & every()

Test if any/all elements pass a condition

javascript
// Test if ANY element passes
const hasEven = [1, 2, 3].some(x => x % 2 === 0);
// true

// Test if ALL elements pass
const allPositive = [1, 2, 3].every(x => x > 0);
// true

// Check for empty array
const isEmpty = array.length === 0 || array.every(x => !x);
💡 Returns boolean, not array elements
⚡ some() stops at first true (OR logic)
⚡ every() stops at first false (AND logic)
📌 Empty array: some() returns false, every() returns true
🔗 Related: includes() for simple value checking

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet