Function findIndex

  • This method is like find except that it returns the index of the first element predicate returns truthy for instead of the element itself.

    Returns

    The index of the found value, else -1

    Example

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

    findIndex(users, (o) => o.user == 'barney')
    // 0

    // The `shape` iteratee shorthand.
    findIndex(users, { 'user': 'fred', 'active': false })
    // 1

    // The `property` iteratee shorthand.
    findIndex(users, 'active')
    // 2

    See

    Type Parameters

    • T

    Parameters

    • obj: T[]

      The array to inspect.

    • fn: Iteratee<T, any, any>

      The predicate function

    • Optional start: number

      The index to search from.

    Returns number

  • Type Parameters

    • T

    Parameters

    • obj: T[]
    • fn: Object
    • Optional start: number

    Returns number

  • Type Parameters

    • T

    Parameters

    • obj: T[]
    • fn: PropertyKey
    • Optional start: number

    Returns number

Generated using TypeDoc