All-items validation
Validate form fields, permissions, or configuration entries before proceeding.
JavaScript · Function
Array.prototype.every() tests array elements with a predicate and returns true only if every visited element passes. It stops at the first failure and returns false; an empty array returns true.
Call every() with a predicate function. JavaScript tests array elements in order and stops as soon as the predicate returns a falsy value; it returns true only when no tested element fails. Sparse-array holes are skipped, and the method can work with array-like objects that provide a length and indexed properties.
every(callbackFn)
every(callbackFn, thisArg)| Name | Type | Description |
|---|---|---|
callbackFn | function | Function called for each eligible element; it should return a truthy value for a pass and a falsy value for a failure. It receives the element, index, and array. |
thisArg | any | Optional value used as this when calling callbackFn. |
true unless the callback returns a falsy value for an element; then false is returned immediately.
true, because there is no element that violates the predicate.const scores = [80, 92, 75];
const allPassed = scores.every((score) => score >= 60);
console.log(allPassed); // trueChecks whether every score meets the passing threshold.
Validate form fields, permissions, or configuration entries before proceeding.
Check that numeric data stays within a required range.
Confirm that every record has required properties or meets a business rule.
Array.prototype.every() return?every() returns a boolean. It returns false immediately when the predicate is falsy for an element; otherwise it returns true after all applicable elements pass.
Follow-up: What happens with []? It returns true, which corresponds to the universal condition having no counterexample.
The callback receives the current element, its index, and the array being traversed. An optional thisArg supplies the callback's this value.
Follow-up: Does the callback visit a sparse array's holes? No; only indexes with assigned values are visited.
every() operate on non-array objects?The method is generic: it only requires a length property and integer-keyed properties on its this value. Therefore, suitable array-like objects can use the method through call or apply.
Follow-up: How does it differ from TypedArray.prototype.every()? The typed-array method uses the same algorithm but is not generic and only applies to typed-array instances.
Array.prototype.some()Array.prototype.filter()Array.prototype.find()Array.prototype.forEach()TypedArray.prototype.every()