Lesson 41 of 48
85%
For Of Loop
for...of walks through values in a list.
Each round gives you the item itself, not just an index.
Think of taking toys out of a box one by one.
1
Loop array values
2
Loop strings
3
Loop Sets and Maps
4
break and continue
Arrays
Write for (const item of array).
javascript
Strings
A string is also a sequence of characters.
for...of can visit each letter.
javascript
Sets
Sets work the same way.
You get each unique value.
javascript
Maps
Looping a Map gives key value pairs.
You can unpack them with brackets.
javascript
Stop early
break and continue work here too.
javascript
Tip: Want values? Use for...of. Want object keys? Use for...in or Object.keys.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.