for...in vs for...of Quiz
Question
What does `for...in` iterate over when used on an array?
Hint
for...in iterates over property keys, not values.
Explanation
for...in iterates over all enumerable property keys (including inherited ones), which for an array are the indices as strings ("0", "1", "2", ...). It does not give the values. Use for...of to iterate over array values. Using for...in on arrays is generally discouraged because it can include non-index properties and does not guarantee order.
Related Resources
Related Lessons
- Loops
Learn about for...in vs for...of.
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.