JS Tutorials
JS Objects
JS Functions
JS Classes
JS Async
Objects that can be iterated over with for..of
are
called iterable.
Technically, iterables must implement the Symbol.iterator
method.
You can use a for..of
loop to iterate over the elements of a
string:
for (const x of "W3Schools") {
// code block to
be executed
}
You can use a for..of
loop to iterate over the elements of
an Array:
for (const x of [1,2,3,4,5] {
// code block to
be executed
}
The iterator protocol defines how to produce a sequence of values from an object.
An object becomes an iterator when it implements a next()
method.
The next()
method must return an object with two properties: