for-of
is a new loop in ES6 that replaces both for-in
and forEach()
and supports the new iteration protocol.
Syntax
Iterating over an Array
Iterating over a String
Difference between for...of
and for...in
The for...in
loop will iterate over all enumerable properties of an object.
The for...of
syntax is specific to collections, rather than all objects.
The following example shows the difference between a for...of
loop and a for...in
loop.
for...in
Example
for...of
Example