Back to course

Iterating Arrays: The Traditional 'for' Loop

JavaScript: The Complete '0 to Hero' Beginner Course

56. Iterating Arrays with the Traditional for Loop

The traditional for loop is the standard, most flexible, and oldest way to loop through arrays. It gives you direct access to the index of each element.

Standard Loop Structure

We start the index at 0, continue while the index is less than the array's length, and increment the index by 1 each time.

javascript const users = ['Mark', 'Jane', 'David', 'Lisa'];

for (let i = 0; i < users.length; i++) { console.log(User ${i + 1} is: ${users[i]}); }

// Output: // User 1 is: Mark // User 2 is: Jane // ...

Why Use the Traditional for Loop?

  1. Flexibility: You can easily stop the loop early using break.
  2. Performance: It is often the fastest loop type.
  3. Control: It allows you to loop backward (i--) or skip elements (i += 2).
  4. Modification: It is the only safe way to modify the array while looping over it (e.g., deleting or adding elements).