Open In App

Lodash _.ary() Method

Last Updated : 13 Nov, 2023
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/


Previous Article
Next Article

Similar Reads

Lodash _.method() Method
Lodash _.method() method creates a function that invokes the method at the path of a given object. Any additional arguments are provided to the invoked method. Syntax: _.method(path, args);Parameters: path: This is the path to invoke.args: These are the arguments to invoke the method with.Return Value: This method returns the new invoker function.
1 min read
Lodash _.flattenDeep() and _.flattenDepth() Method
Lodash _.flattenDeep() Method The _.flattenDeep() method is used to completely flatten nested arrays. It does this recursively. Syntax: _.flattenDeep( array ) Parameters: This method accepts single parameter as mentioned above and described below: array: This parameter holds the array that to be flatten. Return Value: This method returns the new fl
2 min read
Lodash _.dropWhile() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers etc. The Loadsh.dropWhile() method is used to return the slice of the given array. This takes a predicate function that iterate through each element of the array and if the function returns false, it returned the sli
2 min read
Lodash _.stubFalse() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.stubFalse() method is used to always return a false value. The basic difference between using a normal false value and using the _.stubFalse() method is that lambda functions create a new different functi
1 min read
Lodash _.pullAllBy() Method
The _.pullAllBy() method is used to remove the values from the original array by iterating over each element in the array by using the Iteratee function. It is almost the same as _.pullAll() function. Syntax: _.pullAllBy(array, values, [iteratee=_.identity]) Parameters: This method accepts two parameters as mentioned above and described below: arra
2 min read
Lodash _.sortedLastIndexOf() Method
The _.sortedLastIndexOf method is used to return the highest index of the array where an element can be inserted and maintain its sorted order. Also this method is like _.lastIndexOf except that it performs a binary search on a sorted array.Syntax: _.sortedLastIndexOf(array, value) Parameters: This method accepts two parameters as mentioned above a
1 min read
Lodash _.isSymbol() Method
The _.isSymbol() method is used to find whether the given value is a symbol object or not. It returns True if the given value is a symbol object. Otherwise, it returns false. Syntax: _.isSymbol(value) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter holds the value to check. Return Val
1 min read
Lodash _.toArray() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.toArray() method is used to convert the given value to an array. Syntax: _.toArray( value ) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter
1 min read
Lodash _.reduce() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _.reduce() method reduces collection to value which is accumulated result of running each element in the collection through iteratee, where each successive invocation is supplied return value of
2 min read
Lodash _.splitAt() Method
The Lodash _.splitAt() method takes an array and a numeric index and returns a new array containing two embedded arrays made by splitting the original array at the provided numeric index. Syntax: _.splitAt(array, numeric_index) Parameters: This method takes two parameters as mentioned above and described below: array: The array to be split.numeric_
3 min read