findLastIndex source npm

_.findLastIndex(array, [predicate=_.identity])

This method is like _.findIndex except that it iterates over elements of collection from right to left.

Arguments

  1. array (Array)

    The array to search.

  2. [predicate=_.identity] (Function|Object|string)

    The function invoked per iteration.

Returns (number)

Returns the index of the found element, else -1.

Example

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

_.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
// => 2

// using the `_.matches` callback shorthand
_.findLastIndex(users, { 'user': 'barney', 'active': true });
// => 0

// using the `_.matchesProperty` callback shorthand
_.findLastIndex(users, ['active', false]);
// => 2

// using the `_.property` callback shorthand
_.findLastIndex(users, 'active');
// => 0