← JavaScript

for...of Loops

Loops directly over each value in an array, without needing an index.

Understanding for...of Loops in JavaScript

What it does: This is exactly what a for...of loop does. fruit is the variable that stores each value as the loop runs. for...of gives you each value in the array, one at a time. 'of' connects the loop variable to the array being looped over. for...in loops over indexes, not values - they behave differently. JavaScript is case-sensitive, so 'for' must be lowercase. The block of code to repeat is wrapped in { }. n takes on each value of nums directly, without an index.

Common mistakes: 'for' is misspelled as 'Fr'. Use 'of', not 'in', to loop through array values.

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 11–25) and crossword (Modules 21–30) and word search (Modules 1–29) 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...of loop through each value in an array?
YesNo
Matches
for (let n in nums) { ... }
↓
Wrong - use 'of', not 'in', to loop through values
Applying
Meanings
Term
for...of
Meaning
Loops directly over each value in an array, without needing an index.
Practice
let fruits = ["apple", "banana", "cherry"];
Testing
Gaps
(let fruit of fruits) {
Check Answer
Spots
1Fr (let x of arr) {
2console.log(x);

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

The 'Seahorse' badge — Range Rider, 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...of loop through each value in an array?
A. Yes ✓
B. No
for...of gives you each value in the array, one at a time.
2. Does for...of require the keyword 'of'?
A. Yes ✓
B. No
'of' connects the loop variable to the array being looped over.
3. Is 'in' the same as 'of' in this kind of loop?
A. No ✓
B. Yes
for...in loops over indexes, not values - they behave differently.
4. Does for...of need a variable name to hold each value?
A. No
B. Yes ✓
Each value from the array is stored in that variable during the loop.
5. Must 'for' be written in lowercase?
A. No
B. Yes ✓
JavaScript is case-sensitive, so 'for' must be lowercase.

Match the Pairs

for (let fruit of fruits) { ... } → Loops through each value in the fruits array
for (let n of nums) { ... } → Gives direct access to each value in nums, not the index
Loops directly over each value in an array → for...of
Holds the current value during each pass of the loop → let fruit
for (let n in nums) { ... } → Wrong - use 'of', not 'in', to loop through values
For (let n of nums) { ... } → Wrong - 'for' must be lowercase

Key Term

for...of
Loops directly over each value in an array, without needing an index.

Fill in the Blanks

1. for (let fruit of fruits) {
Hint: Type the keyword that starts a for loop.
2. for (let fruit of fruits) {
Hint: Type the keyword that connects the variable to the array.
3. for (let color of colors) {
Hint: Type the keyword that starts a for loop.
4. for (let item of items) {
Hint: Type the keyword used to declare the loop variable.
5. for (let num of nums) {
Hint: Type the symbol that opens the loop's code block.

Spot the Error

Question 1
A Fr (let x of arr) {
B console.log(x);
C }
Line A — 'for' is misspelled as 'Fr'.
Question 2
A let arr = [1,2,3];
B for (let x in arr) {
C console.log(x);
D }
Line B — Use 'of', not 'in', to loop through array values.
Question 3
A let list = [1,2,3];
B for (let v of list) {
C conssole.log(v);
D }
Line C — 'console' is misspelled as 'conssole'.
Question 4
A let nums = [1,2,3];
B for (let n of nums) {
C console.log(n);
D ]
Line D — The block must close with }, not ].
Question 5
A let a = [1,2];
B for (let x of a) {
C console.log(x);
D console.log("done");
E ]
Line E — The block must close with }, not ].

Student with a class code? Join your class →