Skip to the content

Nested data

JavaScript · Unit 7: Objects

An array can hold objects: each item is a whole object. students[1] is the second object, and .name reads one of its properties.

const students = [
  { name: "Ava", score: 9 },
  { name: "Liam", score: 5 },
];
console.log(students[1]);
console.log(students[1].name);

Prints

{ name: 'Liam', score: 5 }
Liam

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. Complete the code

    Complete it to print each student's name.

  3. 3. Predict the output

    What does this code print?

  4. 4. Predict the output

    What does this code print?

  5. 5. Find the bug

    This program should print Mia's city, Denver. Which line has the error?

  6. 6. Multiple choice

    Liam keeps his phone numbers in an array. How do you read the first one?

  7. 7. Predict the output

    What does this code print?

  8. 8. Find the bug

    This program should print each person's city, or undefined if they have no address. Which line has the error?

  9. 9. Complete the code

    Complete it so the function returns the city, or undefined if the person has no address, without crashing.

  10. 10. Put the lines in order

    Order the function that returns the names of those who passed (6 or more).

  11. 11. Predict the output

    Who scored the most goals?

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 →