JavaScript Array at() method
returns element at the given index

at() method takes an integer value and returns the element at that index.

syntax

at(index)

index The index (position) of the array element to be returned.

The first position is 0, the second is 1, ...

Negative integers count back from the last item in the array.

at() method returns element at given index.

at() method returns undefined if the given index cannot be found.

at() method does not change the original array.

at() method is equivalent to the bracket notation when index is non-negative.

myArray.at(0) and myArray[0] both return the first element.

However, when counting elements from the end of the array, you cannot use myArray[-1]

To find the last element in myArray we could use myArray[myArray.length - 1]

at() method allows relative indexing, so this can be shortened to myArray.at(-1) to return the last element in the array.

syntax description
return element at given index in myArray
myArray.at(index)