04. for-of loop
for-of
is a new loop in ES6 that replaces both for-in
and forEach()
that supports the new iteration protocol.
Use it to loop over iterable objects (Arrays, strings, Maps, Sets).
for-of
goes through the items of iterable and assigns them, one at a time, to the loop variable, before it executes the body.The scope of loop variable is the loop, it only exists inside it.
break
andcontinue
work inside for-of loops:
The operand of the of clause must be iterable:
Last updated
Was this helpful?