_.findLastIndex(array, [predicate=_.identity], [fromIndex=array.length-1])
This method is like _.findIndex
except that it iterates over elements of collection
from right to left.
Since
2.0.0
Arguments
-
array
(Array): The array to inspect. -
[predicate=_.identity]
(Function): The function invoked per iteration. -
[fromIndex=array.length-1]
(number): The index to search from.
Returns
(number): Returns the index of the found element, else -1
.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var users = [ { 'user' : 'barney' , 'active' : true }, { 'user' : 'fred' , 'active' : false }, { 'user' : 'pebbles' , 'active' : false } ]; _.findLastIndex(users, function (o) { return o.user == 'pebbles' ; }); // => 2 // The `_.matches` iteratee shorthand. _.findLastIndex(users, { 'user' : 'barney' , 'active' : true }); // => 0 // The `_.matchesProperty` iteratee shorthand. _.findLastIndex(users, [ 'active' , false ]); // => 2 // The `_.property` iteratee shorthand. _.findLastIndex(users, 'active' ); // => 0 |
Please login to continue.