for Loop
JS · Control Flowsyntax
for (init; condition; update) { ... }example
const items = ["apple", "banana", "cherry"];
for (let i = 0; i < items.length; i++) {
console.log(`${i + 1}. ${items[i]}`);
}output
"1. apple"
"2. banana"
"3. cherry"Note Classic loop when you need the index. For simple iteration, prefer for...of. Cache .length in the initializer if the array is very large and not changing.