for (variable of iterable) {
    // code to execute
}
const iterable = [1, 2, 3, 4, 5]; // Iterating Over an Array

for (const item of iterable) {
    console.log(item);
}
The console output will be:
const iterable = "Hello"; // Iterating Over a String

for (const char of iterable) {
    console.log(char);
}
The console output will be:
<div></div>
<div></div>
<div></div>
<div></div>
const elements = document.querySelectorAll("div"); // NodeList

for (const element of elements) {
    console.log(element);
}
The console output will be:
const myArray = [10, 20, 30, 40, 50];

// Using for...of (no index information)
for (const item of myArray) {
    console.log(item);
}

// Using for...in (provides index)
for (const index in myArray) {
    console.log(index, myArray[index]);
}

// Using forEach (value only)
myArray.forEach((item) => {
    console.log(item);
});
const myObject = {
    a: 1,
    b: 2,
    c: 3
}

for (const prop of myObject) {
    console.log(prop);
}
// TypeError: myObject is not iterable
for (const prop in myObject) {
    console.log(myObject[prop]);
}

for (const [key, value] of Object.entries(myObject)) {
    console.log(key, value);
}