Skip to main content

JavaScript Array find — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Array find lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Find the first match

    easy10 min

    Show the first number in the list that is above four.

  2. 2

    Find an object by id

    easy10 min

    Find the user with id 2 and show their name.

  3. 3

    Report no match

    easy10 min

    Show the type of what find gives back when nothing matches.

  4. 4

    Find a position

    easy10 min

    Use findIndex to show where the letter b sits.

  5. 5

    Find the last match

    medium10 min

    Use findLast to show the last number above four.

Find the bug(5)

  1. 1

    Fix filter used instead of find

    easy8 min

    filter gives an array, but a single value is wanted.

  2. 2

    Fix the guard checking for null

    easy8 min

    find returns undefined when nothing matches, not null, so the guard never fires.

  3. 3

    Fix find used for a position

    easy8 min

    The index is wanted, not the value itself.

  4. 4

    Fix the loose id comparison

    easy8 min

    The wrong user is found because the condition compares the wrong property.

  5. 5

    Fix first used instead of last

    easy8 min

    The last match is wanted, not the first.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace