🔰iterator
object that can produce the next iteration result.
has next() method that returns an iteration result. (similar to iterator objects conforming to IteratorProtocol in Swift)
iterators:
str.matchAll() - returns an iterator of matching results.
objects returned by generator functions.
iterators don't always run all the way to the end:
a for-of loop might be terminated with a break, return, or an exception.
when destructuring an iterable, the next() method (of an iterator) is only called enough times to obtain values for each variable.
All iterator protocol methods
return() - give iterator a chance to do "cleanup" actions.
throw()
are expected to return an iteration result object.
iterator for String works correctly with surrogate pairs. 👉 see: str.slice2()
Last updated