โ† Home CP ยท 10-12 ๐Ÿšจ

Neon Patrol

75
Day 1 ๐Ÿ”ฅ
๐ŸŽฏ Today's Missions
๐Ÿšจ ๐ŸŒƒ ๐Ÿ”ฆ ๐Ÿ‘ฎ
NEON CITY UNIVERSE
๐Ÿšจ Neon Patrol
Dragon Array taught you to STORE heroes in a list. Treasure Sorter taught you to ORDER them. Now meet the power to LOCATE any hero instantly โ€” even in a list of 1,000! Use .findIndex() to find WHERE the first matching hero is standing. Real apps use this every second to find users, search lists, and locate data in the blink of an eye!

๐Ÿšจ What is .findIndex()?

.findIndex() scans a list and tells you the position (index) of the FIRST item that matches your rule. Think of it like a superhero radar โ€” you give it a rule, it sweeps the city and shouts back: "Found them at position 3!"

list.findIndex(item => condition) โ€” returns the index number of the match, or -1 if nobody matches.

.filter() returns all matching items. .findIndex() returns the position of the first match. Big difference โ€” one gives you a list, the other gives you a number you can use to point at something!

๐Ÿ”— In Dragon Array you stored heroes with .push(). Now you can locate any hero by their powers. And in Treasure Filter you used .filter() to get matching items โ€” .findIndex() is its position-finding cousin!
patrol.js JavaScript

    
๐Ÿ’ก .findIndex() returns a NUMBER โ€” the position! find โ†’ index โ†’ found!
neon city map LIVE
Patrol Result
Call dispatch to find someone!
Zone
โ€”
Solved
0
Streak
0
Challenge 1 / 4
Build the query to find the hero matching the target. Click Run when ready!
๐Ÿ”ฆ Build Your Patrol Query PATROL DISPATCH
var heroes = [...];
var zone = heroes.findIndex((hero => hero.role === "..."));
Run query to see zone...
๐Ÿ“‹ Your 4 Patrol Cases
0 of 4 cases solved
๐Ÿšจ
You Mastered Neon Patrol!
You used .findIndex() to locate heroes across the neon city! Every search engine, every app with a user list, every game that needs to find something โ€” they all use position-finding code just like this!

๐Ÿ’ซ What You Learned

  • .findIndex(fn) scans a list and returns the position (index) of the first item that matches your rule
  • Returns -1 when nothing matches โ€” always check for this!
  • Unlike .filter() (returns all matches), .findIndex() returns one number โ€” the exact position
  • You can use that position number with list[position] to grab the actual item!