Javascript - .find() and .findIndex()
Code Life
By Pierre Marsaa
Finding One Element
Sometimes you don't want a list, you want one thing. You scan your team's levels looking for a Codémon strong enough to fight, and as soon as you find one, you stop looking.
That's what find does. It takes a test callback like filter, but it returns a single element, not an array:
↗️
Loading editor...
↶
↷
find stops at the first element that passes the test. 15 also passes, but 12 came first, so 12 is returned.
Loading editor...
Verify