Function singleOrDefault

  • Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

    Typeparam

    TSource The type of the elements of source.

    Returns

    The single element of the input sequence that satisfies a condition.

    Type Parameters

    • TSource

    Parameters

    • src: Iterable<TSource>

      An Iterable to return a single element from.

    • Optional predicate: ((item: TSource, index: number) => boolean)

      A function to test an element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns TSource | null

Generated using TypeDoc