Home

function: nth


nth(array: Array, n: number): *

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

Example(s):

const array = ['a', 'b', 'c', 'd']

nth(array, 1)
// => 'b'

nth(array, -2)
// => 'c'

Params:

Name Type Attribute Description
array The array to query.
n The index of the element to return.

Returns:

*

  {
    "comment": "/**\r\n * Gets the element at index `n` of `array`. If `n` is negative, the nth\r\n * element from the end is returned.\r\n *\r\n * @since 4.11.0\r\n * @category Array\r\n * @param {Array} array The array to query.\r\n * @param {number} [n=0] The index of the element to return.\r\n * @returns {*} Returns the nth element of `array`.\r\n * @example\r\n *\r\n * const array = ['a', 'b', 'c', 'd']\r\n *\r\n * nth(array, 1)\r\n * // => 'b'\r\n *\r\n * nth(array, -2)\r\n * // => 'c'\r\n */",
    "meta": {
        "range": [
            501,
            693
        ],
        "filename": "nth.js",
        "lineno": 22,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006445",
            "name": "nth",
            "type": "FunctionDeclaration",
            "paramnames": [
                "array",
                "n"
            ]
        },
        "vars": {
            "length": "nth~length",
            "n": "nth~n"
        }
    },
    "description": "Gets the element at index `n` of `array`. If `n` is negative, the nth\relement from the end is returned.",
    "since": "4.11.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Array",
            "value": "Array"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Array"
                ]
            },
            "description": "The array to query.",
            "name": "array"
        },
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "optional": true,
            "defaultvalue": 0,
            "description": "The index of the element to return.",
            "name": "n"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "*"
                ]
            },
            "description": "Returns the nth element of `array`."
        }
    ],
    "examples": [
        "const array = ['a', 'b', 'c', 'd']\r\rnth(array, 1)\r// => 'b'\r\rnth(array, -2)\r// => 'c'"
    ],
    "name": "nth",
    "longname": "nth",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000602",
    "___s": true,
    "filepath": "nth.js"
}