Returns index of data in an ascended sorted array using a binary search. Returns -1 if data was not found.

indexOf([1,2,3], 3); // 2
indexOf([1,2,3], 0); // -1, not found

By default uses Javascript comparision semantics. Passing in comparer is needed when working with an array of objects.

  • Type Parameters

    • T

    Parameters

    • data: T[]

      Array of data

    • sought: T

      Item to search for

    • start: number = 0

      Start point

    • end: number = data.length

      End index

    • comparer: Comparer<T> = defaultComparer

      Comparer (by default uses JS semantics)

    Returns number

    Index of sought item or -1 if not found.