Lodash _.partial() Method

Lodash _.partial() method is used to create a function that invokes the given func function with prepended partials to the arguments it receives.

Syntax:

_.partial(func, partials);

Parameters:

  • 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: In this example, we are using the _.partial() method to pass ‘w3wiki’ partially.

Javascript




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


Output:

'w3wiki is a computer science portal for Beginner'

Example 2: In this example, we are using the _.partial() method to pass ‘Beginner’ partially.

Javascript




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


Output:

'Hello Beginner'