# \_.findIndex(array, predicate=_.identity , fromIndex=0 )

URL: https://caijiao.org/lodash/docs/Array/_.findIndex
Source: docs/lodash/docs/Array/_.findIndex.md
Description: _.findIndex(array, [predicate=.identity], [fromIndex=0]) 该方法类似 _.find，但它返回的是谓词返回真值的第一个元素的索引，而不是元素本身。

该方法类似 [\_.find](/lodash/docs/Collection/_.find)，但它返回的是谓词返回真值的第一个元素的索引，而不是元素本身。

## 自

1.1.0

## 参数

`array (Array)`： 要检查的数组。

`[predicate=_.identity] (Function)`： 每次迭代调用的函数。

[fromIndex=0]（数字）： 要开始搜索的索引。

## 返回值

(数字）： 返回找到的元素的索引，否则返回-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
```
