# arr.removeDuplicates()

[JS](../../../..) ⟩ [value](../../..) ⟩ [object](../../../obj)⟩ [built-in](../..) ⟩ [Array](..) ⟩ [extension]() ⟩  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](../../../../../appendix/gas/projects/class-average "mention")
* [arr.uniquemerge](arr.uniquemerge "mention")
* [keyword](../../../../grammar/token/keyword "mention") - list all keywords.
* [contextual](../../../../grammar/token/keyword/contextual "mention") - list all contextual keywords.
{% endtab %}

{% tab title="👥 相關" %}
* [set](../../set "mention")
{% endtab %}
{% endtabs %}
