Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Lodash _.partial() Method

  • Last Updated : 13 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 _.partial() method is used to create a function which invokes the given func function with prepended partials to the arguments it receives.

Syntax:

_.partial( func, partials )

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

  • func: This parameter holds the function to partially apply the arguments to.
  • partials: This parameter holds the arguments to be applied. It is an optional parameter.

Return Value: This method returns the new partially applied function.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Given Function
function info(information, name) {
  console.log(information + ' ' + name);
}
  
// Using the _.partial() method  
var call_gfg =
  _.partial(info, 'GeeksforGeeks');
call_gfg('is a computer science portal for geeks');

Output:

'GeeksforGeeks is a computer science portal for geeks'

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Given Function
function info(information, name) {
  console.log(information + ' ' + name);
}
  
// Using the _.partial() method  
var say_gfg = _.partial(info, _, 'geeks');
say_gfg('Hello');

Output:

'Hello geeks'
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!