Thursday, October 23, 2025
HomeLanguagesJavascriptLodash _.rest() Method

Lodash _.rest() 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 _.rest() method is used to create a function that calls the given func with the this binding of the created function along with an array of arguments from the start position and beyond.

Syntax:

_.rest( func, start )

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

  • func: It is the function that is used to apply a rest parameter to.
  • start: It is the start position of the rest parameter. It is an optional parameter.

Return Value: This method returns the new function.

Example 1:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Using the _.rest() method
// with its parameter
var write = _.rest(function(author, portal) {
    return author + portal;
  }, [1]);
  
// Calling write with its values
write(['Nidhi', 'neveropen']);


Output:

Nidhi,neveropen

Example 2:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Using the _.rest() method
// with its parameter
var called = _.rest(function(who, whom) {
    return who + ' ' +
      _.initial(whom).join(', ') +
      (_.size(whom) > 2 ? ', and ' : '') +
      _.last(whom);
  });
   
// Calling called with values 
called('Teacher called', 'nidhi',
       'nisha', 'preeti.');


Output:

Teacher called nidhi, nisha, and preeti.
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS