About Lesson
for…of and for…in Loops
1. for…of
Loops through the values of an iterable object (like an array or string).
Example:
JavaScript
let fruits = ["Apple", "Banana", "Cherry"];
for (let fruit of fruits) {
console.log(fruit); // Prints each fruit
}
2. for…in
Loops through the keys (property names) of an object.
Example:
JavaScript
let person = { name: "Manjeet", age: 25 };
for (let key in person) {
console.log(key + ": " + person[key]); // Prints each key-value pair
}