Gets the element at index n of array. If n is negative, the nth element from the end is returned.
n
array
The array to query.
The index of the element to return.
Returns the nth element of array.
5.7.0
const array = ['a', 'b', 'c', 'd']nth(array, 1)// => 'b'nth(array, -2)// => 'c' Copy
const array = ['a', 'b', 'c', 'd']nth(array, 1)// => 'b'nth(array, -2)// => 'c'
Gets the element at index
n
ofarray
. Ifn
is negative, the nth element from the end is returned.