JavaScript

Choose between Array.some and Array.every

Use some to ask whether at least one entry passes a test, and every to ask whether all entries pass. Both stop once their answer is determined.

Worked example

Node.js example · save as example.mjs and run node example.mjs

const scores = [75, 92, 61];
console.log(scores.some(score => score >= 90));
console.log(scores.every(score => score >= 70));
console.log([].every(() => false));

How it works

Some succeeds on the score 92. Every fails on 61. These methods express existence and universal conditions without building a filtered array. The empty-array case matters: every is true when there are no entries that could fail.

Limits and mistakes

Do not pass async callbacks expecting promises to be awaited. A promise object is truthy, which can produce a misleading result. Resolve asynchronous checks first, then apply some or every to their boolean results.

Check the result

Expect true, false, true. Check an empty input explicitly when an empty selection should be treated as invalid rather than as satisfying all conditions.

Sources

Reference documentation for the behavior used in this guide: