← JavaScript

Objects – for...in Loop

Loops through each key (property name) of an object, one at a time.

Understanding Objects – for...in Loop in JavaScript

What it does: This is exactly what a for...in loop does. Bracket notation with the variable name gets each property's value. Use 'in', not 'of', when looping over an object's properties. Just like other loops, the variable needs let (or const/var). Dot notation only accesses a literal property named 'key' - use obj[key] instead. JavaScript is case-sensitive, so 'for' must be lowercase. 'of' is used for arrays and other iterables, not plain objects.

Common mistakes: 'for' must be lowercase - a capital F causes an error. Use 'in', not 'of', to loop through an object's keys.

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 for...in loop over the keys of an object?
YesNo
Matches
for (let key of obj) { ... }
↓
Wrong - use 'in', not 'of', to loop over an object's keys
Applying
Meanings
Term
for...in
Meaning
Loops through each key (property name) of an object, one at a time.
Practice
let person = {name: "Sam", age: 12};
Testing
Gaps
(let key in person) {
Check Answer
Spots
1For (let k in a) {
2let a = {x: 1};

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

The 'Cosmic Owl' badge — Comprehension Guru, 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 for...in loop over the keys of an object?
A. Yes ✓
B. No
for...in iterates over each property name (key) in the object.
2. Is 'of' used instead of 'in' for looping over an object's keys?
A. Yes
B. No ✓
Use 'in', not 'of', when looping over an object's properties.
3. Must the loop variable be declared with let before 'in'?
A. No
B. Yes ✓
Just like other loops, the variable needs let (or const/var).
4. Does obj[key] access the value for the current key in the loop?
A. Yes ✓
B. No
Bracket notation with the loop variable retrieves each property's value.
5. Does obj.key access the value using the loop variable's value?
A. No ✓
B. Yes
Dot notation only accesses a literal property named 'key' - use obj[key] instead.

Match the Pairs

for (let key in person) { ... } → Loops over each key in the person object
console.log(person[key]); → Accesses the value for the current key using bracket notation
Loops over each property name (key) of an object → for (let key in obj) { ... }
Retrieves a value using the loop's key variable → obj[key]
for (let key of obj) { ... } → Wrong - use 'in', not 'of', to loop over an object's keys
console.log(obj.key); → Wrong - use obj[key], not obj.key, to access the value

Key Term

for...in
Loops through each key (property name) of an object, one at a time.

Fill in the Blanks

1. for (let key in person) {
Hint: Type the keyword that starts a for loop.
2. for (let key in person) {
Hint: Type the keyword that connects the variable to the object's keys.
3. for (let color in car) {
Hint: Type the keyword used to declare the loop variable.
4. for (let prop in obj) {
Hint: Type the keyword that starts a for loop.
5. for (let prop in obj) {
Hint: Type the keyword that connects the variable to the object's keys.

Spot the Error

Question 1
A For (let k in a) {
B let a = {x: 1};
C console.log(k);
D }
Line A — 'for' must be lowercase - a capital F causes an error.
Question 2
A let b = {y: 2};
B for (let k of b) {
C console.log(k);
D }
Line B — Use 'in', not 'of', to loop through an object's keys.
Question 3
A let c = {z: 3};
B for (let k in c) {
C console.log(c.k);
D }
Line C — Use c[k], not c.k, to access the value using the loop variable.
Question 4
A let d = {a: 1};
B for (let k in d) {
C console.log(k);
D ]
Line D — The block must close with }, not ].
Question 5
A let e = {b: 2};
B for (let k in e) {
C console.log(k);
D console.log(e[k]);
E ]
Line E — The block must close with }, not ].

Student with a class code? Join your class →