Lodash - reArg method



Syntax

_.rearg(func, indexes)

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' ]
lodash_function.htm
Advertisements