Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonkemp/find-where
Iterates over a collection of values and returns the first value that matches all of the key-value pairs provided
https://github.com/jonkemp/find-where
array find findwhere util utility
Last synced: 26 days ago
JSON representation
Iterates over a collection of values and returns the first value that matches all of the key-value pairs provided
- Host: GitHub
- URL: https://github.com/jonkemp/find-where
- Owner: jonkemp
- License: mit
- Created: 2020-02-15T14:05:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T14:01:39.000Z (over 2 years ago)
- Last Synced: 2024-09-18T17:13:12.894Z (about 2 months ago)
- Topics: array, find, findwhere, util, utility
- Language: JavaScript
- Size: 195 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# find-where ![Build Status](https://github.com/jonkemp/find-where/actions/workflows/main.yml/badge.svg?branch=master)
> Iterates over a collection of values and returns the first value that matches all of the key-value pairs provided.
If no match is found, or if the collection is empty, `undefined` will be returned.
Inspired by `_.findWhere`. 😄
## Install
Install with [npm](https://npmjs.org/package/find-where)
```
$ npm install find-where
```Or [unpkg](https://unpkg.com/find-where/)
```
```
Check out the unit tests on [CodePen](https://codepen.io/jonkemp/full/rNVeVKE).
## Usage
```js
const findWhere = require('find-where');const users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': true }
];findWhere(users, { 'age': 1 });
//=> { 'user': 'pebbles', 'age': 1, 'active': true }findWhere(users, { 'user': 'barney' });
//=> { 'user': 'barney', 'age': 36, 'active': true }findWhere(users, { 'age': 36, 'active': true });
//=> { 'user': 'barney', 'age': 36, 'active': true }
```---
| **Like us a lot?** Help others know why you like us! **Review this package on [pkgreview.dev](https://pkgreview.dev/npm/find-where)** | âž¡ | [![Review us on pkgreview.dev](https://i.ibb.co/McjVMfb/pkgreview-dev.jpg)](https://pkgreview.dev/npm/find-where) |
| ----------------------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------------------------------------------------------------------------------------- |## API
### findWhere(collection, properties)
#### collection
Type: `array`
Default: `none`The array to iterate over.
#### properties
Type: `object`
Default: `none`The key-value pairs to match.
## License
MIT