For
The easiest form of a loop is the for statement. This one has a syntax that is similar to an if statement, but with more options:
Let's see how to execute the same code ten-times using a for
loop:
Note:
i = i + 1
can be writteni++
.
To loop through the properties of an object or an array for in
loop can also be used.
Examples of for in
loop for an object and array is shown below:
The value of iterable objects such as Arrays
, Strings
, Maps
, NodeLists
can be looped using for of
statement.
Last updated
Was this helpful?