https://github.com/codewell/retrieve-from-array
Retrieve an object from an array with objects using a filter object
https://github.com/codewell/retrieve-from-array
Last synced: 10 months ago
JSON representation
Retrieve an object from an array with objects using a filter object
- Host: GitHub
- URL: https://github.com/codewell/retrieve-from-array
- Owner: codewell
- License: mit
- Created: 2019-11-20T12:48:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T01:18:41.000Z (over 3 years ago)
- Last Synced: 2025-07-25T06:43:12.537Z (11 months ago)
- Language: JavaScript
- Size: 658 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @codewell/retrieve-from-array
Retrieve an object from an array with objects using a filter object
## Installation
```
npm install @codewell/retrieve-from-array
```
## Basic usage
```JavaScript
import retrieveFromArray from '@codewell/retrieve-from-array';
const arr1 = [
{ foo: '1', bar: 'a', id: '1a' },
{ foo: '2', bar: 'b', id: '2b' },
{ foo: '3', bar: 'c', id: '3c' },
];
retrieveFromArray(arr1, { id: '3c' });
// => [{ foo: '3', bar: 'c', id: '3c' }]
// All fields in the filter needs to match
retrieveFromArray(arr2, { foo: '2', bar: 'b' });
// => [{ foo: '2', bar: 'b', id: '2b' }]
```