Iterator.prototype[Symbol.iterator]() - JavaScript | MDN
Syntax
js
iterator[Symbol.iterator]()
Parameters
None.
Return value
The value of this, which is the iterator object itself.
Examples
Iteration using for...of loop
Note that you seldom need to call this method directly. The existence of the [Symbol.iterator]() method makes built-in iterators iterable, and iterating syntaxes like the for...of loop automatically call this method to obtain the iterator to loop over.
js
const arrIterator = [1, 2, 3].values();
for (const value of arrIterator) {
console.log(value);
}
// Logs: 1, 2, 3
Specifications
| Specification |
|---|
| ECMAScript® 2027 Language Specification # sec-%iteratorprototype%-%symbol.iterator% |