> 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/arr/ext/arr.removeduplicates.md).

# arr.removeDuplicates()

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [object](/web/js/val/obj.md)⟩ [built-in](/web/js/val/builtin.md) ⟩ [Array](/web/js/val/builtin/arr.md) ⟩ [extension](/web/js/val/builtin/arr/ext.md) ⟩  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="⬇️ 應用" %}

* [各班平均及前三名](/web/appendix/gas/projects/class-average.md)
* [arr.uniqueMerge()](/web/js/val/builtin/arr/ext/arr.uniquemerge.md)
* [keyword](/web/js/grammar/token/keyword.md) - list all keywords.
* [contextual keyword](/web/js/grammar/token/keyword/contextual.md) - list all contextual keywords.
  {% endtab %}

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

* [Set](/web/js/val/builtin/set.md)
  {% endtab %}
  {% endtabs %}
