Lodash – reArg method

  • Post author:
  • Post category:Lodash
  • Post comments:0 Comments
Lodash - reArg method

Syntax Of Lodash reArg method

_.rearg(func, indexes)

Lodash reArg method creates a function that invokes func with arguments arranged according to the specified indexes where the argument value at the first index is provided as the first argument, the argument value at the second index is provided as the second argument, and so on.

Arguments

  • func (Function) − The function to rearrange arguments for.
  • indexes (…(number|number[])) − The arranged argument indexes.

Output

  • (Function) − Returns the new function.

Example

var _ = require('lodash');
var rearged = _.rearg(function(a, b, c) {
   return [a, b, c];
}, [2, 0, 1]);
 
console.log(rearged('b', 'c', 'a'));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 'a', 'b', 'c' ]

Next Topic – Click Here

Leave a Reply