Lodash _.nthArg() Method
Lodash _.nthArg() method Creates a function that gets the argument at index n. If n is negative, the nth argument from the end is returned.
Syntax:
_.nthArg(n);
Parameters:
- n: The index of the argument to return.
Returns:
It returns the new pass-thru function.
Example 1: In this example, we are getting the value of index 1 of the given array.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.nthArg() method let func = _.nthArg(1); let gfg = func( 'www' , 'Beginner' , 'for' , 'Beginner' ); // Printing the output console.log(gfg); |
Output :
Beginner
Example 2: In this example, we are getting the value of index -4 which is the value from the end of the given array.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.nthArg() method let func = _.nthArg(-4); let gfg = func( 'www' , 'Beginner' , 'for' , 'Beginner' ); // Printing the output console.log(gfg); |
Output:
www
Contact Us