Looping Through a List
Visit every item in your array.
Looping a List 🔁📋
Hi, list explorer! 🌟 What if we want to see EVERY item in a list?
We use a special loop called for-of! It visits each item. 🪄
let pets = ["cat", "dog", "fish"]
for (let pet of pets) {
console.log(pet)
}The for-of Loop 🚶
for (let item of list) walks through the list, one item at a time!
Each turn, item is the next thing in the list. 👣
let fruits = ["apple", "banana", "grape"]
for (let fruit of fruits) {
console.log(fruit)
}All lessons in this course
- What Is an Array?
- Getting Items by Number
- Adding and Removing Items
- Looping Through a List