@mirei/ts-collections
    Preparing search index...

    Function elementAtOrDefault

    • Retrieves the element at the specified zero-based index or returns null when the index is out of range.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • index: number

        Zero-based position of the element to retrieve.

      Returns TElement | null

      The element at index, or null when source is shorter than index + 1 or when index is negative.

      Use this overload when out-of-range access should produce a sentinel value instead of throwing an exception.

      const numbers = [1, 2, 3, 4, 5];
      const element = elementAtOrDefault(numbers, 2);
      console.log(element); // 3

      const element2 = elementAtOrDefault(numbers, 10);
      console.log(element2); // null