# arr.removeDuplicates()

[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) ⟩ [Array](https://lochiwei.gitbook.io/web/js/val/builtin/arr) ⟩ [extension](https://lochiwei.gitbook.io/web/js/val/builtin/arr/ext) ⟩  arr.removeDuplicates()

{% tabs %}
{% tab title="💾 程式" %}

* [replit](https://replit.com/@pegasusroe/array-remove-duplicates#index.js)

```javascript
Object.defineProperties(Array.prototype, {
    // 🔹 .removeDuplicates()
    removeDuplicates: {
        value: function() {
            return [... new Set(this)];    // new array (non-mutating)
        },
    },
});
```

{% endtab %}

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

```javascript
[ 1, 1, 2, 3, 2, 3, 4 ].randomElement,       // (random)
[ 1, 1, 2, 3, 2, 3, 4 ].removeDuplicates(),  // [ 1, 2, 3, 4 ]
[1].concat([1,2,3],[2,3,4]),                 // [ 1, 1, 2, 3, 2, 3, 4 ]
[1].union([1,2,3],[2,3,4]),                  // [ 1, 2, 3, 4 ]
```

{% endtab %}

{% tab title="⬇️ 應用" %}

* [class-average](https://lochiwei.gitbook.io/web/appendix/gas/projects/class-average "mention")
* [arr.uniquemerge](https://lochiwei.gitbook.io/web/js/val/builtin/arr/ext/arr.uniquemerge "mention")
* [keyword](https://lochiwei.gitbook.io/web/js/grammar/token/keyword "mention") - list all keywords.
* [contextual](https://lochiwei.gitbook.io/web/js/grammar/token/keyword/contextual "mention") - list all contextual keywords.
  {% endtab %}

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

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