Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,21 @@
---
title: Filter unique array values
type: snippet
tags: [array]
cover: tulips-and-reeds
dateModified: 2020-11-02T19:41:00+02:00
---
Creates an array with the unique values filtered out.
- Use the `Set` constructor and the spread operator (`...`) to create an array of the unique values in `arr`.
- Use `Array.prototype.filter()` to create an array containing only the non-unique values.
```js
const filterUnique = arr =>
[...new Set(arr)].filter(i => arr.indexOf(i) !== arr.lastIndexOf(i));
```
```js
filterUnique([1, 2, 2, 3, 4, 4, 5]); // [2, 4]
```