JavaScript Iterator Reference
The Iterator Object
AnIterator is an object that provides a standard way to access elementssequentially.
An Iterator must adheres to theIterator Protocol and must have anext() method.
The Iterator.from() Method
TheIterator.from()creates an iterator object from an existing iterable or iterator object.
Example
const myIterator = Iterator.from("123456789");
// Iterate over all elements
let text = "";
for (const x of myIterator) {
text += x;
}
Note
Technically, iterables must implement theSymbol.iterator method.
In JavaScript the following are iterables:
- Strings
- Arrays
- Typed Arrays
- Sets
- Maps
Because their prototype objects have aSymbol.iterator method:
Helper Functions
JavaScript 2025 (ECMAScript 2025) officially approved a set of new Iterator Helper methods thatsignificantly enhance the functionality of iterators in #"jsref_iterator_drop.asp">drop()
true if all elements satisfy a provided test functiontrue if at least one element satisfy a test function
