Iterables and for...of Loop in JavaScript

SchleifenDOM-Einführung

An iterable is any object that can be looped over – like arrays and strings. The for...of loop is the modern, clean way to iterate over values in iterables.

This is different from for...in, which loops over property names (keys).

The for...of Loop

Gives you each value directly – no need for index.

Strings Are Iterable

Maps and Sets

Map iterates over entries, Set over unique values.

for...in – For Object Properties

for...in loops over enumerable property names (keys) – mainly for objects.

Avoid for...in on arrays – it loops over indices as strings and can include inherited properties.

When to Use Which Loop

  • for – known number of iterations, need index.
  • while/do-while – condition-based, unknown repetitions.
  • for...of – clean value iteration over iterables.
  • for...in – object property enumeration.

Quick Quiz

Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.

✨ Frag Lara — deine KI-Lernpartnerin

Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.


Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

Verfolge deinen Fortschritt 🚀

Lerne einfacher, indem du deinen Fortschritt kostenlos verfolgst.