Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/component/find
Return the first matching value in an array
https://github.com/component/find
Last synced: 13 days ago
JSON representation
Return the first matching value in an array
- Host: GitHub
- URL: https://github.com/component/find
- Owner: component
- Created: 2012-09-30T21:18:01.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-04-06T21:27:40.000Z (over 9 years ago)
- Last Synced: 2024-12-08T20:13:18.203Z (20 days ago)
- Language: JavaScript
- Size: 104 KB
- Stars: 12
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# find
Find the first matching value in an array.
## Installation
$ component install component/find
## API
### find(array, fn)
Find with a function:
```js
var tobi = find(users, function(u){ return u.name == 'Tobi' });
```### find(array, string)
Find with property strings:
```js
find(users, 'admin');
```### find(array, object)
Find with object value matching:
```js
var users = [];
users.push({ name: 'Tobi', age: 2, species: 'ferret' });
users.push({ name: 'Jane', age: 6, species: 'ferret' });
users.push({ name: 'Luna', age: 2, species: 'cat' });find(users, { name: 'Jane', age: 6 });
// => { name: 'Jane', age: 6, species: 'ferret' }find(users, { name: 'Jane', age: 1 });
// => undefined
```# License
MIT