Description

Get the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned.

Syntax

nth(array, n)

Parameters

Input ParameterTypeDescription
arrayArrayThe array to query.
nnumberThe index of the element to return.

Return value

Type
any

Sample

ExampleResultDescription
nth(['a', 'b', 'c', 'd'], 2)'c'Returns 2nd index (3rd) value.
nth(['a', 'b', 'c', 'd'], -1)'d'Returns 1st value from the end

To view all the List functions, click here.

See Also

get