nth

Retrieves the element at a specified index from an array.

(nth index arr)

Returns

The function returns the element at the specified index in the given array.

Parameters

index (number) - the index of the element to retrieve from the array

arr (array) - the array from which the element is to be retrieved.

  • The index can be positive or negative.

  • If the absolute value of the specified index exceeds the length of the array it will be divided by the array length

Examples

(nth 1 [1, 2, 3, 4, 5])        
;;=> 2

(nth -1 ["John", "Pop", "Maria"])
;;=> Maria

Was this helpful?