Files
30-seconds-of-code/snippets/uniqueElements.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

16 lines
295 B
Markdown

---
title: uniqueElements
tags: array,beginner
---
Returns all unique values of an array.
Use ES6 `Set` and the `...rest` operator to discard all duplicated values.
```js
const uniqueElements = arr => [...new Set(arr)];
```
```js
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
```