@nevware21/ts-utils
    Preparing search index...

    Function arrAt

    • The arrAt() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array. This is an ES2022 feature with polyfill support for older environments.

      Type Parameters

      • T

        Identifies the type of array elements

      Parameters

      • theArray: ArrayLike<T>

        The array or array-like object to get element from

      • index: number

        The index of the element to return. Negative index counts from the end

      Returns T

      The element at the specified index, or undefined if index is out of range

      0.14.0

      arrAt([1, 2, 3, 4, 5], 0);      // 1
      arrAt([1, 2, 3, 4, 5], 2); // 3
      arrAt([1, 2, 3, 4, 5], -1); // 5
      arrAt([1, 2, 3, 4, 5], -2); // 4
      arrAt([1, 2, 3], 10); // undefined
      arrAt([1, 2, 3], -10); // undefined

      // Array-like objects
      arrAt({ length: 3, 0: "a", 1: "b", 2: "c" }, -1); // "c"