find2

Array find first value utility

find

Find the first matching value in an array.

$ component install component/find

Find with a function:

var tobi = find(users, function(u){ return u.name == 'Tobi' });

Find with property strings:

find(users, 'admin');

Find with object value matching:

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 });
// =>  

License

MIT