Lodash - nthArg method



Syntax

_.nthArg([n=0])

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

Arguments

  • [n=0] (number) − The index of the argument to return.

Output

  • (Function) − Returns the new pass-thru function.

Example

var _ = require('lodash');
var func = _.nthArg(1);
console.log(func('a', 'b', 'c', 'd'));

func = _.nthArg(2);
console.log(func('a', 'b', 'c', 'd'));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

b
c
lodash_util.htm
Advertisements