Function nthArg

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

    Parameters

    • Optionaln: number

      The index of the argument to return.

    Returns (<T>(...args: T[]) => T | undefined)

    Returns the new pass-thru function.

      • <T>(...args): T | undefined
      • Type Parameters

        • T

        Parameters

        • Rest...args: T[]

        Returns T | undefined

    4.0.0

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

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