# arr-filter-unique

> Helper function to filter unique items in arrays

Latest version **1.1.2** (published 2019-08-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install arr-filter-unique
pnpm add arr-filter-unique
yarn add arr-filter-unique
bun add arr-filter-unique
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2019-08-21 |
| First published | 2019-07-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Raschid J.F. Rafaelly |
| Maintainers | raschidjfr |
| Keywords | array, filter, unique |

## Links

- npm: https://www.npmjs.com/package/arr-filter-unique
- Repository: https://github.com/RaschidJFR/arr-filter-unique
- Homepage: https://github.com/RaschidJFR/arr-filter-unique#readme
- Issues: https://github.com/RaschidJFR/arr-filter-unique/issues
- npm.io page: https://npm.io/package/arr-filter-unique

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2019-08-21
- 1.1.1 — 2019-08-20
- 1.1.0 — 2019-07-28
- 1.0.0 — 2019-07-25

## README

💡 Filter unique elements in arrays!

```js
function arrFilterUnique(array, key = undefined)
```

## Usage


Simplest use:

```js
const arrFilterUnique = require('arr-filter-unique');
// For typescript use: import * as arrFilterUnique from 'arr-filter-unique';

arrFilterUnique([1, 1, 2, 3, 3, 4, 5, 5]);
// [1, 2, 3, 4, 5]
```

Filter elements by id:

```js
arrFilterUnique([{ id: 1 }, { id: 1 }, { id: 2 }], 'id');
// [{id: 1}, {id: 2}]
```

Filter by a deeper property:

```js
const movies = [
  {
    title: 'Pretty Woman',
    starring: {
      name: 'Julia',
      lastname: 'Roberts'
    },
  {
    title: '17 Again',
    starring: {
      name: 'Matthew',
      lastname: 'Perry'
    },
  {
    title: 'The Smurfs',
    starring: {
      name: 'Katy',
      lastname: 'Perry'
    }
];

const uniqueLastnameMovies = arrFilterUnique(movies, 'starring.lastname');
// [{
// title: 'Pretty Woman',
// starring: {
//   name: 'Julia',
//   lastname: 'Roberts'
// },
// {
// title: '17 Again',
// starring: {
//   name: 'Matthew',
//   lastname: 'Perry'
// }]


// Now I would just want the lastnames:
const uniqueLastnames = uniqueLastnameMovies.map(movie => movie.starring.lastname);
// ['Roberts', 'Perry']
```

### API
| Parameter | Type     | Needed | Description                                                                                    |
| --------- | -------- | ------ | ---------------------------------------------------------------------------------------------- |
| `array`   | `any[]`  | yes    | The array to filter                                                                            |
| `key`     | `string` | no     | If provided, objects are compared by this key. Can use dot notation: `path.to.identifying.key` |


**Returns:** The filtered array with no repeated elements (according to the identifying key passed).

## Contribute
Hope this helps you. Feel free to clone and send PR 🙂

## Credits
Raschid JF. Rafaelly

<hello@raschidjfr.dev>

https://raschidjfr.dev

---
_Source: https://npm.io/package/arr-filter-unique · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
