freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #22 of 61

array methods · find · findIndex · some · every

LambdaVSThe Mutator
Lambda saysfind, findIndex, some, and every search and test arrays.

find returns the first matching item (findIndex its index); both return undefined/-1 if none match. some returns true if any item passes; every if all do. They short-circuit — stopping as soon as the answer is known — which makes them efficient.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleFind the first user over 18, then check if every user is active.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const ages=[12,17,21,30]; const first=ages.find(a=>a>=18); const allAdult=ages.every(a=>a>=18);
document.getElementById('o').textContent='first adult='+first+' allAdult='+allAdult;</script></body></html>
▶ Open the interactive comic issue
‹ Array Methods · Map · Filter · ReduceArray Methods · Sort · Reverse ›