For...of vs For...in
Multiple Choice Easy
Question
Which loop iterates over array values (not indices)?
Hint
for...of gives values, for...in gives keys.
Explanation
for...of iterates over iterable values (array elements, string characters). for...in iterates over property names (object keys or array indices as strings). For arrays, always use for...of to get values. Using for...in on arrays can give unexpected results including inherited properties.
Related Resources
Related Lessons
- Loops
Learn JS loops.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.