> 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/val/builtin/set.md).

# Set

🚧 under construction

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [object](/web/js/val/obj.md)⟩ [built-in](/web/js/val/builtin.md) ⟩ Set

{% hint style="info" %}
[⭐️ ES6 (2015)](/web/js/feature/es6.md)
{% endhint %}

{% tabs %}
{% tab title="⭐️" %}
{% hint style="info" %}

* <mark style="color:purple;">**Set**</mark> is [iterable](/web/js/iteration/iterable.md).
  {% endhint %}
  {% endtab %}

{% tab title="💈" %}

```javascript
// array -> set
const s = new Set([1, 2, 3, 4])

// set -> array
[...s]          // [1, 2, 3, 4]                      
```

{% endtab %}

{% tab title="🔸" %}
instance methods:

* [add(value)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add) - 將元素加入集合中。
* [delete(value)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete) - 刪除元素。
* [clear()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear) - 清除集合。
* [has(value)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has) - 元素是否在集合中。

iteration methods:

* values()
* keys()
* entries()
* forEach()
  {% endtab %}

{% tab title="👥 相關" %}

* [Array](/web/js/val/builtin/arr.md) / [Map](/web/js/val/builtin/map.md)
  {% endtab %}

{% tab title="📗 參考" %}
\*
{% endtab %}

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

* MDN ⟩ [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
  {% endtab %}
  {% endtabs %}
