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

    • n: number = 0

      The index of the argument to return.

    Returns <T>(array: T[], n?: number) => T

    Returns the new pass-thru function.

      • <T>(array: T[], n?: number): T
      • Gets the element at index n of array. If n is negative, the nth element from the end is returned.

        Type Parameters

        • T

        Parameters

        • array: T[]

          The array to query.

        • n: number = 0

          The index of the element to return.

        Returns T

        Returns the nth element of array.

        5.7.0

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

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

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

    5.10.0

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

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