A for-of loop goes through each element in an array, one by one.
for (const item of array) {
// code runs for each item
}
The variable (item) gets each value from the array:
const numbers = [10, 20, 30];
const doubled = [];
for (const num of numbers) {
doubled.push(num * 2);
}
// doubled is [20, 40, 60]
A string is just a list of characters, so for...of walks through it one character at a
time:
const letters = [];
for (const letter of "cat") {
letters.push(letter);
}
// letters is ["c", "a", "t"]
const for the loop variable (it changes each iteration)