# Set

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [value](https://lochiwei.gitbook.io/web/js/val) ⟩ [object](https://lochiwei.gitbook.io/web/js/val/obj)⟩ [built-in](https://lochiwei.gitbook.io/web/js/val/builtin) ⟩ Set

{% hint style="info" %}
[es6](https://lochiwei.gitbook.io/web/js/feature/es6 "mention")
{% endhint %}

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

* <mark style="color:purple;">**Set**</mark> is [iterable](https://lochiwei.gitbook.io/web/js/iteration/iterable "mention").
  {% 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="👥 相關" %}

* [arr](https://lochiwei.gitbook.io/web/js/val/builtin/arr "mention") / [map](https://lochiwei.gitbook.io/web/js/val/builtin/map "mention")
  {% endtab %}

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

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

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