Lodash – rest method

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

Syntax Of Lodash rest method

_.rest(func, [start=func.length-1])

The Lodash rest method creates a function that invokes func with the binding of the created function and arguments from start and beyond provided as an array.


  • func (Function) โˆ’ The function to apply a rest parameter to.
  • [start=func.length-1] (number) โˆ’ The start position of the rest parameter.


  • (Function) โˆ’ Returns the new function.


var _ = require('lodash');

var say = _.rest(function(what, names) {
   return what + ' ' + _.initial(names).join(', ') + (_.size(names) > 1 ? ' & ' : '') + _.last(names);
console.log(say('Hello', 'Joe', 'Tom', 'Julie'));

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


\>node tester.js


Hello Joe, Tom & Julie

Next Topic – Click Here

Leave a Reply