Options
All
  • Public
  • Public/Protected
  • All
Menu

Module findIndex

Index

References

Functions Array

References

Renames and re-exports findIndex

Array Functions

  • findIndex(array: any, predicate?: any, fromIndex?: number): number
  • 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

    5.2.0

    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

    Parameters

    • array: any

      The array to inspect.

    • Optional predicate: any

      The function invoked per iteration.

    • Optional fromIndex: number

      The index to search from.

    Returns number

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