Saturday, November 15, 2025
HomeLanguagesJavascriptLodash _.wrap() Method

Lodash _.wrap() Method

The _.wrap() method of Function in lodash is used to create a function that delivers value to the stated wrapper like its initial argument. Moreover, any further arguments delivered to the function are added to those which are delivered to the stated wrapper.

Note:

  • The wrapper used here is called with the this binding of the function formed.

Syntax:

_.wrap(value, [wrapper=identity])

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

  • value: It is the value to be wrapped.
  • wrapper: It is the wrapper function.

Return Value: This method returns the new function.

Below examples illustrate the Lodash _.wrap() method in JavaScript:

Example 1:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Calling wrap() method with its parameter
var res = _.wrap(_.escape, function(functn, txt) {
  return '<b>' + functn(txt) + '</b>';
});
   
// Assigning values
res('GfG, neveropen, & neveropen');


Output:

<b>GfG, neveropen, &amp; neveropen</b>

Example 2:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Calling wrap() method with its parameter
var newfn = _.wrap(_.upperCase, function(x, y) {
  return x(y)
});
  
// Assigning values
newfn("neveropen");


Output:

GEEKSFORGEEKS

Reference: https://lodash.com/docs/4.17.15#wrap

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
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS