Open In App

Lodash _.ary() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.ary() method is used to create a function that invokes the given function, up to n arguments, ignoring any additional arguments.

Syntax:

_.ary( func, n )

Parameters:

This method accepts two parameters as mentioned above and described below:

  • func: This parameter holds the function which will cap arguments for.
  • n: This parameter holds the number n which element will be capped.

Return Value:

This method returns the new capped function.

Note: If you use 0 it will cap each element.

Example 1: The below example illustrates the Lodash _.ary() method:

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Applying _.ary() method
let gfg =_.map(['6', '8', '10'],
        _.ary(parseInt, 2));
 
console.log(gfg);


Output:

[ 6, NaN, 2 ]

Example 2: The below example illustrates the Lodash _.ary() method:

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Applying _.ary() method
let gfg =_.map(['6', '8', '10'],
        _.ary(parseInt, 1));
 
console.log(gfg);


Output:

[ 6, 8, 10 ]

Reference: https://docs-lodash.com/v4/ary/


Last Updated : 13 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads