JavaScript for...of Loop Guide

JavaScript Logo

for…of Loop – Iterates over **iterable values** (arrays, strings, NodeLists). Cleaner than a for‑loop when you don't need the index.

๐Ÿ‘‰ Syntax

for (const value of iterable) {
  // value is each element
}

๐Ÿงช Example

const colors = ['red', 'green', 'blue'];
for (const c of colors) {
  console.log(c.toUpperCase());
}

Comments