Imagine ranger binoculars sweeping across the herd, left to right. The moment an animal matches your clue — stop! That's .find(). It returns the first item that passes the test, and ignores everything after it.
What vs Where: In Neon Patrol you learned .findIndex() — it gives you the WHERE (a position number). .find() gives you the WHAT (the item itself)!
What if nothing matches? .find() returns undefined — the ranger saw nothing today. Always check before using the result:
And .includes()? It doesn't care WHERE or WHAT — it just answers yes or no (true/false). Perfect for simple values like strings and numbers:
Remember: In Gem Vault, .filter() kept ALL matches as a new array. .find() stops at the FIRST match and returns just that one item. Many results → filter. One result → find!
Scan the list and stop at the FIRST number greater than 10!
Same test, two superpowers: .find() gives the item, .findIndex() gives the position!
.includes() just answers true or false — no position, no item!
When no animal passes the test, .find() returns undefined. Guard it with an if!
Master move! First .filter() to keep only predators, then .find() the first one faster than 100!
.find() — Returns the FIRST item that passes your test, then stops scanning.find() vs .findIndex() — find gives you WHAT, findIndex gives you WHEREundefined — What find returns when nothing matches (guard with if!).includes() — A simple true/false check: is this value in the array?.filter().find(): narrow the herd, then spot the first match!