Nested data
JavaScript · Unit 7: Objects
- Full plan
- JavaScript
- 11 exercises
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 }
LiamThe 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. Predict the output
What does this code print?
2. Complete the code
Complete it to print each student's name.
3. Predict the output
What does this code print?
4. Predict the output
What does this code print?
5. Find the bug
This program should print Mia's city, Denver. Which line has the error?
6. Multiple choice
Liam keeps his phone numbers in an array. How do you read the first one?
7. Predict the output
What does this code print?
8. Find the bug
This program should print each person's city, or
undefinedif they have no address. Which line has the error?9. Complete the code
Complete it so the function returns the city, or
undefinedif the person has no address, without crashing.10. Put the lines in order
Order the function that returns the names of those who passed (6 or more).
11. Predict the output
Who scored the most goals?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.