give iterator a chance to perform cleanup actions.
JS⟩ iteration ⟩ iterator ⟩ return()
this method is invoked automatically when the iteration is stopped prematurel, it is where you can perform cleanup actions.
calling this method tells the iterator that the caller does not intend to make any more next() calls and can perform any cleanup actions.
the return() method must return an iteration result object:
properties of the returned object are ignored
it is an error to return a non-object value
Sequence - custom iterable of numbers.
JavaScript Tutorial ⟩ The Essential Guide to JavaScript Iteratorsarrow-up-right ⭐️
the iterator protocolarrow-up-right
Last updated 3 years ago