A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-ntharg-method/ below:

Lodash _.nthArg() Method - GeeksforGeeks

Lodash _.nthArg() Method

Last Updated : 03 Nov, 2023

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: 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', 'geeks', 'for', 'geeks');

// Printing the output  
console.log(gfg);

Output :

geeks

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', 'geeks', 'for', 'geeks');

// Printing the output  
console.log(gfg);

Output:

www


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4