Function at

  • 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-like.

    Type Parameters

    • T extends ArrayLike<unknown>

    Parameters

    • array: undefined | null | T

      The array-like to search.

    • index: number

      The index of the item to return.

    Returns undefined | T[number]

    The item at the given index.

    Example

    Basic usage

    at(["a", "b"], 0) // "a"
    at(["a", "b"], 1) // "b"
    at(["a", "b"], 9) // undefined
    at(["a", "b"], -1) // "b"
    at(["a", "b"], -2) // "a"
    at(["a", "b"], -9) // undefined

    at("bar", 2) // "r"
    at("bar", -1) // "r"

    at(null, 0) // undefined
    at(undefined, 1) // undefined

Generated using TypeDoc