🔸return()

give iterator a chance to perform cleanup actions.

JSiterationiterator ⟩ 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

Last updated