1.0.6 • Published 2 years ago

find-where v1.0.6

Weekly downloads
8
License
MIT
Repository
github
Last release
2 years ago

find-where Build Status

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

$ npm install find-where

Or unpkg

<script src="https://unpkg.com/find-where@1.0.4/umd/index.js" />

Check out the unit tests on CodePen.

Usage

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.devReview us on pkgreview.dev

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

1.0.6

2 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.1-0

4 years ago