Iterate Values
for...of iterates over values from arrays, strings, maps, sets, and other iterables.
It is the most readable way to loop over arrays when you only need values.
JavaScript Tutorial
The for...of loop iterates over values in arrays and other iterables.
It is clean, readable, and avoids manual indexing.
Most of the time you care about values, not indexes. for...of keeps that intent clear.
It also works with strings, maps, and sets, so it is versatile.
for (const value of iterable) { ... }const items = ["a", "b", "c"];
for (const item of items) {
console.log(item);
}for...of iterates values directly.
const word = "code";
for (const char of word) {
console.log(char);
}Each iteration yields one character.
for...of iterates over values from arrays, strings, maps, sets, and other iterables.
It is the most readable way to loop over arrays when you only need values.
for...of can iterate over string characters one by one.
This is useful for parsing and validation.
You can use break and continue inside for...of loops.
This gives you full control over the iteration.
Without
const items = ["a", "b"];
for (let i = 0; i < items.length; i++) {
console.log(items[i]);
}With
const items = ["a", "b"];
for (const item of items) {
console.log(item);
}Objects are not iterable; use Object.keys or for...in instead.
Use entries() or a classic for loop for indices.
Be careful when adding or removing items during the loop.
Values from any iterable like arrays or strings.
Use array.entries() and destructure index and value.
It is more readable when you only need values.
Practice: Loop through an array of names and print each one.
const names = ["Ava", "Lee", "Ravi"];
// TODO: print each name
One Possible Solution
const names = ["Ava", "Lee", "Ravi"];
for (const name of names) {
console.log(name);
}Any iterable: arrays, strings, maps, sets, and more.
Use array.entries() or a traditional for loop.
Yes, just like other loops.
Try iterating different arrays and strings with for...of.