🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## find + [link](./find "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L7619 "View in source.") + [npm](https://www.npmjs.com/package/lodash.find "See the npm package.") ``` _.find(collection, [predicate=_.identity]) ``` 遍历集合中的元素,返回最先经 `predicate` 检查为真值的元素。 predicate 会传入3个元素:(value, index|key, collection)。 ### 参数 1. collection (Array|Object) 要检索的集合 2. [predicate=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (\*) 返回匹配元素,否则返回 `undefined` ### 示例 ``` var users = [ { 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'fred', 'age': 40, 'active': false }, { 'user': 'pebbles', 'age': 1, 'active': true } ]; _.find(users, function(o) { return o.age < 40; }); // => 结果: 'barney' // 使用了 `_.matches` 的回调结果 _.find(users, { 'age': 1, 'active': true }); // => 结果: 'pebbles' // 使用了 `_.matchesProperty` 的回调结果 _.find(users, ['active', false]); // => 结果: 'fred' // 使用了 `_.property` 的回调结果 _.find(users, 'active'); // => 结果: 'barney' ```