Function findIndexAll

  • Get an array of all indexes of elements in an array that passed a given predicate.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array to search in

    • predicate: (element: T, index: number) => boolean

      The function to call for each element to decide whether it should be included in the result

    Returns number[]

    An array of indexes of elements that passed predicate in array

    findIndexAll([1, 2, 1, 3, 1], (element) => element === 1); // [0, 2, 4]
    

    indexOfAll if you want to find all elements equal to a given value

    Array