Function findLastIndex

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

    Parameters

    • array: any

      The array to inspect.

    • Optional predicate: any

      The function invoked per iteration.

      Optional
    • Optional fromIndex: number

      The index to search from.

      Optional

    Returns number

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

    Since

    5.2.0

    Example


    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