Function findIndex

  • Returns the index of the first element in the array where predicate is true, and -1 otherwise.

    Type Parameters

    • T

    Parameters

    • array: readonly T[]
    • compare: ((value) => boolean)
        • (value): boolean
        • Parameters

          • value: T

          Returns boolean

    Returns number

    Example

    const obj = [{name: 'abc'}]
    const index = findIndex(obj, v => v.name = 'abc')
    // 0