Thursday, January 22, 2026
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
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS