Looping Through Arrays

Learn how to do something to every item in an array using for loops, .forEach(), and .map().

Step 1 of 6

Why we need loops

Imagine you have an array of 100 student names and you need to print each one. You could write 100 `console.log()` statements — but that's absurd. What if the list grows to 1,000? Or what if you don't know the length in advance?

Loops solve this: they let you run the same code once for every item in an array, automatically. You write the action once, and the loop repeats it for each element. This is one of the most powerful ideas in programming — doing repetitive work without repetitive code.

Every web app uses loops constantly: rendering a list of search results, displaying chat messages, iterating through shopping cart items, processing form data.

Think of it this way: Looping is like a mail carrier walking down a street — they stop at each house (array item), do their job (deliver mail), then move to the next one. They don't need separate instructions for each house; the same routine repeats at every stop.
Learn more on MDN
JAVASCRIPTREAD ONLY
CONSOLE
Click "Run" to execute your code...