https://github.com/phalt/uniqueobj
Remove duplicates from an array of objects
https://github.com/phalt/uniqueobj
Last synced: 10 months ago
JSON representation
Remove duplicates from an array of objects
- Host: GitHub
- URL: https://github.com/phalt/uniqueobj
- Owner: phalt
- License: gpl-3.0
- Created: 2020-02-10T20:49:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-11T20:30:44.000Z (over 6 years ago)
- Last Synced: 2025-02-23T19:11:35.715Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/uniqueobj
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# uniqueObj
Given an iterable of objects, return a unique list of the objects. You define how each object is identified with a callback.
## Install
```sh
npm install uniqueObj
```
## Usage
### `uniqueObj([iterable,], callBack)`
Takes an iterable of `Object`.
`callBack` will be called against each item in the iterable to determine it's uniqueness. Here you can hash the object, or do any logic to determine the uniqueness of it.
```js
import uniqueObj from 'uniqueObj';
// just use the `id` value in each object to identify it
uniqueResults = uniqueObj(allResults, (obj) => obj.id);
// Do something a bit more complicated
uniqueResults = uniqueObj(allResults, myComplicatedHashFunc);
```
## License
GNU GPL V3