Loops in JavaScript
From the JavaScript cheat sheet ยท Control Flow ยท verified Jul 2026
Loops
for, while, do-while, for...of, for...in, break, and continue
javascript
for (let i = 0; i < 5; i++) { }
while (condition) { }
for (const item of array) { } // iterate values
for (const key in object) { } // iterate keys๐ก for...of iterates VALUES (arrays, strings, Maps, Sets) โ use for most loops
โก for...in iterates KEYS/properties (objects) โ avoid on arrays, use for...of instead
๐ break exits the loop entirely; continue skips to the next iteration
๐ข for...of works on any iterable โ arrays, strings, Maps, Sets, generators