_.nth(array, [n=0])

sourcenpm package

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

Since

4.11.0

Arguments

  • array (Array): The array to query.
  • [n=0] (number): The index of the element to return.

Returns

(*): Returns the nth element of array.

Example

  1. var array = ['a', 'b', 'c', 'd'];
    _.nth(array, 1);
    // => 'b'
    _.nth(array, -2);
    // => 'c';