Rename js snippets

This commit is contained in:
Angelos Chalaris
2023-05-19 20:23:47 +03:00
parent 82a614e42e
commit 9d032ce05e
305 changed files with 70 additions and 70 deletions

View File

@ -0,0 +1,21 @@
---
title: Unique values in array
type: snippet
language: javascript
tags: [array]
cover: shelf-plant
dateModified: 2020-10-22T20:24:44+03:00
---
Finds all unique values in an array.
- Create a `Set` from the given array to discard duplicated values.
- Use the spread operator (`...`) to convert it back to an array.
```js
const uniqueElements = arr => [...new Set(arr)];
```
```js
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
```