for

for

Description

for (mixed init; mixed condition; [mixed final])

Parameters

Name Description Type Default Optional
init mixed No
condition mixed No
final mixed Yes

Examples

Example #1 – for example

Iteration between two values.

for (var i = 1; i <= 5; i++) { console.log(i); }

Increment the value inside the loop.

for (var i = 1; i <= 5;) { console.log(i++); }
Example #2 – for example

Iterate over an array.

var a = ['Foo', 'Bar']; for (var i = 0; i < a.length; i++) { console.log(a[i]); }

External references