Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Lodash _.rearg() Method

  • Last Updated : 29 Sep, 2020

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.rearg() method in lodash is used to create a function that calls func parameter with the arguments that are organized according to the stated indexes. Where, the argument valued at the first index is sent as the first argument, the argument valued at the second index is sent as the second argument, and so on.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

_.rearg(func, indexes)

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



  • func: It is the function which is used to reorganize the arguments for.
  • indexes: It is the indexes of organized argument.

Return Value: This method returns the new function.

Example 1:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Calling rearg() method with its parameter
var fn = _.rearg(function(x, y, z) {
  return [x, y, z];
}, [2, 1, 0]);
   
// Calling fn
fn('z', 'y', 'x');

Output:

[ 'x', 'y', 'z' ]

Example 2:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Calling rearg() method with its parameter
var concat = _.rearg(function(Geeks, forGeeks) {
  return (Geeks+forGeeks);
}, [1, 0]);
   
// Calling concat
concat('forGeeks', 'Geeks');

Output:

GeeksforGeeks

Reference: https://lodash.com/docs/4.17.15#rearg




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!