> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/array/findindex.md).

# \_.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`的简写法
