# \_.find（查找数组或对象中符合条件的值）

**语法：**

```javascript
_.find(collection, [predicate=_.identity], [fromIndex=0])
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L9212)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.find)

**描述：**

遍历`collection`（集合）元素，返回`predicate`（断言函数）第一个返回真值的第一个元素。predicate（断言函数）调用3个参数：*(value, index|key, collection)*。

**开始版本：**&#x30;.1.0

**参数：**

* `collection (Array|Object)`: 一个用来迭代的集合。
* `[predicate=_.identity] (Array|Function|Object|string)`: 每次迭代调用的函数。
* `[fromIndex=0] (number)`: 开始搜索的索引位置。

**返回值：**

* `(*)`: 返回匹配元素，否则返回 undefined。

**例子：**

```javascript
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; });
// => object for 'barney'

// The `_.matches` iteratee shorthand.
_.find(users, { 'age': 1, 'active': true });
// => object for 'pebbles'

// The `_.matchesProperty` iteratee shorthand.
_.find(users, ['active', false]);
// => object for 'fred'

// The `_.property` iteratee shorthand.
_.find(users, 'active');
// => object for 'barney'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lodash.shujuwajue.com/collection/find.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
