JavaScript’s for
loop is the same as that in C and Java: it lets you provide the control information for your loop on a single line.
for (let i = 0; i < 5; i++) {
// Will execute 5 times
}
JavaScript also contains two other prominent for loops: for
…of
and for
…in
For of
for (let value of array) {
// do something with value
}
For in
The for...in
statement iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements. A for...in
statement looks as follows:
for (variable in object)
statement