Two methods answer yes/no questions about a whole array. Both take a callback that returns true or false for each item.
some: is there at least one?
const prices = [12, 8, 45, 20];
console.log(prices.some(price => price > 40)); // → true
console.log(prices.some(price => price > 100)); // → false
some returns true as soon as one item passes, and stops looking.
every: do all of them pass?
const ages = [21, 34, 19, 52];
console.log(ages.every(age => age >= 18)); // → true
console.log(ages.every(age => age >= 20)); // → false
every returns false as soon as one item fails.
Empty arrays
console.log([].some(x => x > 0)); // → false
console.log([].every(x => x > 0)); // → true
An empty array has no item that passes (some is false) and no item that fails (every is true). Keep this in mind when an empty list should block something.
Real examples
const cart = [
{ name: "Book", inStock: true },
{ name: "Pen", inStock: false }
];
const canCheckout = cart.every(item => item.inStock);
const hasOutOfStock = cart.some(item => !item.inStock);
console.log(canCheckout); // → false
console.log(hasOutOfStock); // → true
A form check:
const fields = [
{ name: "email", value: "maya@example.com" },
{ name: "name", value: "" }
];
const allFilled = fields.every(field => field.value.trim() !== "");
console.log(allFilled); // → false
Instead of a loop with a flag
Without these methods, you would write a loop and a variable:
let found = false;
for (const price of prices) {
if (price > 40) { found = true; break; }
}
prices.some(price => price > 40) says the same in one line, and it reads like a question.
Related methods
find returns the matching item, filter returns all matching items, some and every return a yes or no. See Searching Arrays and filter().