Skip to the content

Searching

JavaScript · Unit 8: More on arrays

find searches an array for the first item that meets a condition and hands it to you. The condition is an arrow function, like in filter.

If none of them meets it, you get undefined.

const nums = [4, 9, 12, 7];
const big = nums.find((n) => n > 8);
console.log(big);

Prints

9

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Predict the output

    What does this code print?

  3. 3. Complete the code

    Complete it to print Liam's grade.

  4. 4. Predict the output

    What does this code print?

  5. 5. Multiple choice

    You have an array of items, each with a name and a price. Which method hands you the bread object directly, so you can read its price?

  6. 6. Predict the output

    What does this code print?

  7. 7. Complete the code

    Complete it so it says "All done" only if every chore is done.

  8. 8. Find the bug

    This program should warn you if there are minors in the group. There is one here, aged 15. Which line has the error?

  9. 9. Find the case that fails

    priceOf(items, name) should return the price of the item with that name, or 0 if it isn't there. Which call does it fail with?

  10. 10. Put the lines in order

    Order the function that returns the name of the first student who passed (6 or more). There's always at least one.

  11. 11. Predict the output

    You check what you still need to buy for a recipe. What does it print?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →