Tuesday, December 31, 2024
Google search engine
HomeLanguagesJavascriptLodash _.arity() Method

Lodash _.arity() Method

The Lodash _.arity() method returns a new function which is equivalent to the given function, except that the new function’s length property is equal to the number of Arguments. This does not limit the function to using that number of arguments. Its only effect is on the reported length.

Syntax:

_.arity( numberOfArgs, fun )

Parameters: This method takes two parameters as listed above and discussed below.

  • numberOfArgs: This parameter takes a number stating the number of arguments the method will take.
  • fun: This is the given function.

Return Value: It returns a new function.

Note: To execute the below examples, you have to install the lodash-contrib library by using this command prompt and execute the following command.

npm install lodash-contrib

Example 1: 

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(){
    return "neveropen";
}
  
var gfgFunc = _.arity(4,fun);
  
console.log("Length of function is :",
    gfgFunc.length);
console.log("Function content :",
    gfgFunc());


Output:

Length of function is : 4
Function content : neveropen

Example 2:

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(){
    return arguments[0]*10;
}
  
var gfgFunc = _.arity(4,fun);
  
console.log("Length of function is :",
    gfgFunc.length);
console.log("Function content :",
    gfgFunc(10));


Output: 

Length of function is : 4
Function content : 100

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments