Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

JavaScript Dictionary

  1. Home
  2. JavaScript Dictionary
  3. Array .some() / every()

Array .some() / every() Since: ES5(ECMAScript 2009)

Methods that check whether elements in an array satisfy a condition. some() returns true if at least one element satisfies the condition; every() returns true only if all elements satisfy the condition.

Syntax

// Checks whether at least one element satisfies the condition.
var result = array.some(function(element, index, array) {
	return condition;
});

// Checks whether all elements satisfy the condition.
var result = array.every(function(element, index, array) {
	return condition;
});

Method List

MethodDescription
some(function)Returns true if at least one element in the array satisfies the condition. Returns false if no elements satisfy the condition. Always returns false for an empty array.
every(function)Returns true if all elements in the array satisfy the condition. Returns false if any element does not satisfy the condition. Always returns true for an empty array.

Sample Code

var scores = [65, 80, 42, 90, 75];

// Checks whether at least one score is 90 or above.
var hasExcellent = scores.some(function(score) {
	return score >= 90;
});
console.log(hasExcellent); // Outputs: true

// Checks whether all scores are 50 or above.
var allPassed = scores.every(function(score) {
	return score >= 50;
});
console.log(allPassed); // Outputs: false — 42 does not meet the condition.

// Example: validating form fields.
var fields = ["Taro", "taro@example.com", ""];
var hasEmpty = fields.some(function(field) {
	return field === "";
});
console.log(hasEmpty); // Outputs: true — there is an empty field.

var allFilled = fields.every(function(field) {
	return field !== "";
});
console.log(allFilled); // Outputs: false

Overview

array.some() and array.every() are methods for evaluating a condition against an entire array. Both use short-circuit evaluation — they stop iterating as soon as the result is determined. array.some() stops when it finds an element that returns true; array.every() stops when it finds an element that returns false. This makes both methods efficient even for large arrays.

For form validation, you can use array.every() to confirm that all fields are filled in, and array.some() to detect whether any field is empty. Both methods are also useful for permission checks and conditional branching.

Be aware of how these methods behave with empty arrays. array.some() always returns false for an empty array, while array.every() always returns true. This behavior is based on the concept of "vacuous truth" in mathematical logic. If you need to retrieve the matching elements themselves rather than just a boolean result, use array.find() / array.filter().

Browser Compatibility

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
1 or earlier ×
Safari Safari
18+
2 or earlier ×
Edge Edge
80+
11 or earlier ×
IE IE
11+
8 or earlier ×
Opera Opera
48+
9 or earlier ×
iOS Safari iOS Safari
18+
Supported in all versions
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .