> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/iteration/iterator/return.md).

# return()

give iterator a chance to perform cleanup actions.

[JS](/web/js.md)⟩ [iteration](/web/js/iteration.md) ⟩ [iterator](/web/js/iteration/iterator.md) ⟩ return()

{% hint style="success" %}
this method is <mark style="color:yellow;">**invoked**</mark>**&#x20;**<mark style="color:red;">**automatically**</mark> when the [iteration](/web/js/iteration.md) is <mark style="color:yellow;">**stopped**</mark>**&#x20;**<mark style="color:red;">**prematurel**</mark>, it is where you can perform <mark style="color:orange;">**cleanup**</mark> actions.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}
calling this method tells the [iterator](/web/js/iteration/iterator.md) that <mark style="color:yellow;">**the caller**</mark>**&#x20;**<mark style="color:red;">**does not intend**</mark>**&#x20;**<mark style="color:yellow;">**to make any more**</mark> [next()](/web/js/iteration/iterator/next.md) calls and can perform any <mark style="color:orange;">**cleanup**</mark> actions.
{% endhint %}

{% hint style="danger" %}
the <mark style="color:purple;">**return()**</mark> method must return an [iteration result](/web/js/iteration/iteration-result.md) object：

* <mark style="color:yellow;">**properties**</mark> of the returned object are <mark style="color:red;">**ignored**</mark>
* it is an <mark style="color:red;">**error**</mark> to return a <mark style="color:yellow;">**non-object**</mark> value
  {% endhint %}
  {% endtab %}

{% tab title="💈範例" %}

* [Sequence](/web/js/iteration/iterable/custom/sequence.md) - custom iterable of numbers.
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] JavaScript Tutorial ⟩ [The Essential Guide to JavaScript Iterators](https://www.javascripttutorial.net/es6/javascript-iterator/) ⭐️
  {% endtab %}

{% tab title="📘 手冊" %}

* [the iterator protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterator_protocol)
  {% endtab %}
  {% endtabs %}
