Nested Arrays and Objects, online

Six activities your students do on their own devices. See who's finished, and their scores.

Nested Arrays and Objects in one minute

What students need to know

The first bracket picks a row, the second picks a column. The bracket picks the object, then the dot reads its property.

This chains dot notation and bracket notation to reach the nested value. You can mix .property and [index] to reach deeply nested values.

Mistakes students make

  • Missing the dot before pets - it should be obj.pets[0].
  • Missing the dot before addr - it should be obj.addr.
  • Arrays use square brackets [], not round brackets ().
  • Object literals close with }, not ].
PREVIOUS · MODULE 34Objects – for...in Loop
YOU ARE HERE · MODULE 35Nested Arrays and Objects
NEXT · MODULE 36Destructuring

Discover other journeys with this module

What students will learn in this module

Every question in Module 35

Quick questions

  1. Does person.pets[0] access an element nested inside an object?ANoBYes
  2. Can dot notation and bracket notation be chained together?AYesBNo
  3. Does grid[0][1] access an element in a 2D array?ANoBYes
  4. Is users.0.name valid syntax for accessing an array element?ANoBYes
  5. Does obj.addr.city access a property nested two levels deep?AYesBNo

Key terms

Students type the meaning of:

  • obj.pets[0]

Match the pairs

obj.pets[0]Match it to what it does
obj.addr.cityMatch it to what it does
Accesses an element in a 2D array using two indexesMatch it to what it does
Accesses a property on an object stored inside an arrayMatch it to what it does
users.0.nameMatch it to what it does
obj.addr[city]Match it to what it does

Fill in the blanks

  1. console.log(person.pets_0]);

    Hint: Type the symbol that opens an index access on the nested array.

  2. console.log(obj.addr_city);

    Hint: Type the symbol that connects addr to its nested property.

  3. console.log(users[0]_name);

    Hint: Type the symbol that connects the array element to its property.

  4. console.log(data.scores[_]);

    Hint: Type the index of the third element in scores.

  5. console.log(grid[0]_1]);

    Hint: Type the symbol that opens the second index access.

Spot the error

Question 1

Aconsole.log(objpets[0]);Blet obj = {};Cobj.pets = ["Rex", "Mia"];

Question 2

Aobjaddr = {city: "NYC"};Blet obj = {};Cconsole.log(obj.addr.city);

Question 3

Alet obj = {};Bobj.pets = ("Rex", "Mia");Cconsole.log(obj.pets[0]);

Question 4

Alet obj = {};Bobj.addr = {city: "NYC"];Cconsole.log(obj.addr.city);

Question 5

Alet obj = {};Bobj.pets = ["Rex", "Mia"];Cconsole.log(obj.pets.0);