.findIndex(array, [predicate=.identity], [fromIndex=0])
This method is like _.find
except that it returns the index of the first element predicate
returns truthy for instead of the element itself.
Since
1.1.0
Arguments
array
(Array): The array to inspect.[predicate=.identity]
(Function)_: The function invoked per iteration.[fromIndex=0]
(number): The index to search from.
Returns
(number): Returns the index of the found element, else -1
.
Example
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
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .