1var baseMatches = require('../internal/baseMatches'), 2 find = require('./find'); 3 4/** 5 * Performs a deep comparison between each element in `collection` and the 6 * source object, returning the first element that has equivalent property 7 * values. 8 * 9 * **Note:** This method supports comparing arrays, booleans, `Date` objects, 10 * numbers, `Object` objects, regexes, and strings. Objects are compared by 11 * their own, not inherited, enumerable properties. For comparing a single 12 * own or inherited property value see `_.matchesProperty`. 13 * 14 * @static 15 * @memberOf _ 16 * @category Collection 17 * @param {Array|Object|string} collection The collection to search. 18 * @param {Object} source The object of property values to match. 19 * @returns {*} Returns the matched element, else `undefined`. 20 * @example 21 * 22 * var users = [ 23 * { 'user': 'barney', 'age': 36, 'active': true }, 24 * { 'user': 'fred', 'age': 40, 'active': false } 25 * ]; 26 * 27 * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user'); 28 * // => 'barney' 29 * 30 * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user'); 31 * // => 'fred' 32 */ 33function findWhere(collection, source) { 34 return find(collection, baseMatches(source)); 35} 36 37module.exports = findWhere; 38 39