These two answer questions about the whole array, and return a simple true or false:
some: "Does at least one item pass the test?"every: "Do all the items pass the test?"
const scores = [72, 85, 49, 91];
console.log(scores.some((s) => s < 50));
console.log(scores.every((s) => s >= 50));
console.log(scores.every((s) => s > 0));
It prints
true false true
Is anyone failing? Yes (some found the 49). Is everyone passing? No. Are all scores positive? Yes.
const cart = [
{ item: "rice", inStock: true },
{ item: "oil", inStock: true },
{ item: "sugar", inStock: false },
];
if (cart.every((product) => product.inStock)) {
console.log("✅ Ready to check out!");
} else {
console.log("⚠️ Some items are out of stock.");
}
It prints
⚠️ Some items are out of stock.