for / for-in
Counting and iterating over collections.
Syntax
for (var i=0; i<n; i++) // for (var x in items)
Description
The classic for loop runs a specific number of times. for-in gives each element of a list/set in order — you don't have to deal with indices.
Example
Loading editor…
Expected output
1 2 3 a b
When to use?
List processing, repetitive tasks.