every()
every<
T>(collection,predicate):boolean
every<
T>(collection,predicate):boolean
Checks if predicate returns truthy for all elements of collection.
Use array.every() or Object.values().every() directly instead.
Type Parametersโ
T: Tโ
The type of elements in the array, or the object type.
Parametersโ
Overload 1:
collection: T[]โ
The collection to iterate over.
predicate: (value, index, array) => booleanโ
The function invoked per iteration.
Overload 2:
collection: Tโ
The collection to iterate over.
predicate: (value, key, object) => booleanโ
The function invoked per iteration.
Returns: booleanโ
true if all elements pass the predicate check, else false.
See Alsoโ
Sinceโ
2.0.0
Also known asโ
all (Ramda) ยท every (Lodash, es-toolkit, Effect) ยท โ (Remeda, Radashi, Modern Dash, Antfu)
Exampleโ
const numbers = [1, 2, 3, 4, 5];
// โ Deprecated approach
const allPositive = every(numbers, n => n > 0);
console.log(allPositive); // true
// โ
Recommended approach (for arrays)
const allPositiveNative = numbers.every(n => n > 0);
console.log(allPositiveNative); // true
// โ
Recommended approach (for objects)
const obj = { a: 1, b: 2, c: 3 };
const allPositiveObj = Object.values(obj).every(n => n > 0);
console.log(allPositiveObj); // true
How it works?โ
Checks if all elements pass the predicate.
Deprecated: Use array.every() directly.
Native Equivalentโ
// โ every(arr, fn)
// โ
arr.every(fn)
Use Casesโ
Validate all items match criteria ๐โ
Check if all elements satisfy a condition.
const ages = [18, 25, 30, 22];
ages.every(age => age >= 18);
// => true
Check form validityโ
Verify all form fields are valid.
const fields = [{ value: "a" }, { value: "b" }, { value: "" }];
fields.every(f => f.value.length > 0);
// => false
Ensure permissions grantedโ
Check if all required permissions are granted.
const permissions = ["read", "write", "execute"];
const granted = ["read", "write", "execute"];
permissions.every(p => granted.includes(p));
// => true
Validate uploaded files meet constraintsโ
Check that all files in an upload batch respect size and type limits. Essential for file upload forms, document management, and media libraries.
const maxSize = 5 * 1024 * 1024; // 5MB
const allowedTypes = ["image/png", "image/jpeg", "application/pdf"];
const files = [
{ name: "photo.jpg", size: 2_000_000, type: "image/jpeg" },
{ name: "doc.pdf", size: 1_500_000, type: "application/pdf" },
{ name: "huge.png", size: 8_000_000, type: "image/png" },
];
const allValid = every(files, (f) => f.size <= maxSize && allowedTypes.includes(f.type));
// => false (huge.png exceeds 5MB)