Home

function: nthArg


nthArg(n: number): function

Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned.

Example(s):

const func = nthArg(1)
func('a', 'b', 'c', 'd')
// => 'b'

const func = nthArg(-2)
func('a', 'b', 'c', 'd')
// => 'c'

Params:

Name Type Attribute Description
n The index of the argument to return.

Returns:

function

  {
    "comment": "/**\r\n * Creates a function that gets the argument at index `n`. If `n` is negative,\r\n * the nth argument from the end is returned.\r\n *\r\n * @since 4.0.0\r\n * @category Util\r\n * @param {number} [n=0] The index of the argument to return.\r\n * @returns {Function} Returns the new pass-thru function.\r\n * @example\r\n *\r\n * const func = nthArg(1)\r\n * func('a', 'b', 'c', 'd')\r\n * // => 'b'\r\n *\r\n * const func = nthArg(-2)\r\n * func('a', 'b', 'c', 'd')\r\n * // => 'c'\r\n */",
    "meta": {
        "range": [
            492,
            551
        ],
        "filename": "nthArg.js",
        "lineno": 21,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006492",
            "name": "nthArg",
            "type": "FunctionDeclaration",
            "paramnames": [
                "n"
            ]
        },
        "vars": {
            "": null
        }
    },
    "description": "Creates a function that gets the argument at index `n`. If `n` is negative,\rthe nth argument from the end is returned.",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Util",
            "value": "Util"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "optional": true,
            "defaultvalue": 0,
            "description": "The index of the argument to return.",
            "name": "n"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "Returns the new pass-thru function."
        }
    ],
    "examples": [
        "const func = nthArg(1)\rfunc('a', 'b', 'c', 'd')\r// => 'b'\r\rconst func = nthArg(-2)\rfunc('a', 'b', 'c', 'd')\r// => 'c'"
    ],
    "name": "nthArg",
    "longname": "nthArg",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000606",
    "___s": true,
    "filepath": "nthArg.js"
}