← JavaScript

Nested Arrays and Objects

Chains dot notation and bracket notation to access a value nested inside an object.

Understanding Nested Arrays and Objects in JavaScript

What it does: 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. Two bracket accesses in a row reach into an array of arrays. Array indexes need brackets: users[0].name, not a dot. Each dot goes one level deeper into the nested object. Without quotes, city is read as a variable, not a property name.

Common mistakes: Missing the dot before pets - it should be obj.pets[0]. Missing the dot before addr - it should be obj.addr.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 31–40) and word search (Modules 21–52).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does person.pets[0] access an element nested inside an object?
YesNo
Matches
users.0.name
↓
Wrong - array indexes use brackets, not dots
Applying
Meanings
Term
obj.pets[0]
Meaning
Chains dot notation and bracket notation to access a value nested inside an object.
Practice
let person = {name: "Sam", pets: ["Rex", "Mia"]};
Testing
Gaps
console.log(person.pets0]);
Check Answer
Spots
1console.log(objpets[0]);
2let obj = {};

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Kangaroo Rat' badge — Speed Typer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does person.pets[0] access an element nested inside an object?
A. No
B. Yes ✓
This chains dot notation and bracket notation to reach the nested value.
2. Can dot notation and bracket notation be chained together?
A. Yes ✓
B. No
You can mix .property and [index] to reach deeply nested values.
3. Does grid[0][1] access an element in a 2D array?
A. No
B. Yes ✓
Two bracket accesses in a row reach into an array of arrays.
4. Is users.0.name valid syntax for accessing an array element?
A. No ✓
B. Yes
Array indexes need brackets: users[0].name, not a dot.
5. Does obj.addr.city access a property nested two levels deep?
A. Yes ✓
B. No
Each dot goes one level deeper into the nested object.

Match the Pairs

obj.pets[0] → Accesses the first element of the pets array inside obj
obj.addr.city → Accesses the city property nested inside addr inside obj
Accesses an element in a 2D array using two indexes → grid[0][1]
Accesses a property on an object stored inside an array → users[0].name
users.0.name → Wrong - array indexes use brackets, not dots
obj.addr[city] → Wrong - a nested property needs a dot, not unquoted brackets

Key Term

obj.pets[0]
Chains dot notation and bracket notation to access a value nested inside an object.

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[2]);
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
A console.log(objpets[0]);
B let obj = {};
C obj.pets = ["Rex", "Mia"];
Line A — Missing the dot before pets - it should be obj.pets[0].
Question 2
A objaddr = {city: "NYC"};
B let obj = {};
C console.log(obj.addr.city);
Line A — Missing the dot before addr - it should be obj.addr.
Question 3
A let obj = {};
B obj.pets = ("Rex", "Mia");
C console.log(obj.pets[0]);
Line B — Arrays use square brackets [], not round brackets ().
Question 4
A let obj = {};
B obj.addr = {city: "NYC"];
C console.log(obj.addr.city);
Line B — Object literals close with }, not ].
Question 5
A let obj = {};
B obj.pets = ["Rex", "Mia"];
C console.log(obj.pets.0);
Line C — Use bracket notation obj.pets[0], not a dot, for an array index.

Student with a class code? Join your class →