---
description: 'infinite sequence: 0, 1, 2, 3, ...'
---

# \*integers()

[JS](../../..)⟩ [iteration](../..) ⟩ [custom generators]() ⟩ \*integers()

{% hint style="success" %}
[infinite](../../iterator/infinite) sequence: <mark style="color:yellow;">**0, 1, 2, 3, ...**</mark>
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}
:floppy\_disk: replit：[integers()](https://replit.com/@pegasusroe/generator-non-negative-integers#integers.js)

🌀 extension： [iterator](../../iterator/iterator "mention") - extend built-in [iterable](../../iterator/iterable "mention")s.

```javascript
// ⭐️ infinite sequence: 0, 1, 2 ... 
function* integers() {
    let i = 0;
    while (true) { yield i++ }
}
```

💈範例：

```javascript
// ⭐️ iterable destructuring
const [a, b, c] = integers();
console.log(a, b, c);            // 0, 1, 2
```
{% endtab %}

{% tab title="👥 相關" %}
* [destruct](../../../grammar/op/assign/destruct "mention")
* similar objects：
  * [closedrange](../../iterable/custom/closedrange "mention") - range of integers (the hard way)
  * [closedrange](closedrange "mention") - range of integers (generator: the easy way)
  * [list](list "mention") - finite arithmetic sequence
  * [sequence](../../iterable/custom/sequence "mention") - sequence of numbers.
{% endtab %}

{% tab title="⬇️ 應用" %}
* used in the <mark style="color:yellow;">**example**</mark> of&#x20;
  * [zip](zip "mention")
  * [interleave](interleave "mention")
  * [seq](seq "mention")
{% endtab %}
{% endtabs %}
