JAVASCRIPT CLIMBSChapter 4 · JS Collections Depth
For Of and For In
JavaScript provides loops tailored to specific data shapes: for...of (loops through array elements directly) and for...in (loops through the keys of an object).
Worked example
How it reads
- for (const star of stars) iterates over the elements themselves
- for (const key in config) iterates over the object's keys

Cloud tip: Never use for...in to loop over arrays; it iterates over index strings, which can lead to unexpected type conversion errors.


