# \_.findIndex（查找元素索引值）

**语法：**

```javascript
_.findIndex(array, [predicate=_.identity], [fromIndex=0])
```

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

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

**描述：**

这个方法l类似于[`_.find`](https://lodash.com/docs/4.17.10#find)，但是只是返回差找到第一次的索引值，而不是返回值本身。

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

**参数：**

* `array (Array)`: 需要检索的数组。
* `[predicate=_.identity] (Function)`: 每个迭代函数调用。
* `[fromIndex=0] (number)`: 开始搜索的索引值。

**返回值：**

* `(number)`: 返回查找到的元素索引值，否则ｆ返回 `-1`。

**例子：**

```javascript
var users = [
  { 'user': 'barney',  'active': false },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': true }
];

_.findIndex(users, function(o) { return o.user == 'barney'; });
// => 0

// The `_.matches` iteratee shorthand.
_.findIndex(users, { 'user': 'fred', 'active': false });
// => 1

// The `_.matchesProperty` iteratee shorthand.
_.findIndex(users, ['active', false]);
// => 0

// The `_.property` iteratee shorthand.
_.findIndex(users, 'active');
// => 2
```

注意：不同的方式代表：`_.matches`，`_.matchesProperty`，`_.property`的简写法


---

# 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/array/findindex.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.
