🔰iterator

JSiteration ⟩ iterator

⭐️ ES6 (2015)

object that can produce the next iteration result.

iterators

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