Skip to main content


TS JS Deno

Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

Use Array.prototype.every() to test if all elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.

const all = <T = any>(arr: T[], fn: (t: T) => boolean = Boolean) =>
assertEquals(all([1, 2, 3, 4]), true);
assertEquals(all([2, null, 1]), false);

const hasName = (user: any) => Boolean(;
assertEquals(all([{ name: "D" }, { name: "D2" }], hasName), true);
assertEquals(all([{ name: "D" }, { name: "" }], hasName), false);