Friday, July 24, 2026
HomeLanguagesJavascriptLodash _.prototype.plant() Method

Lodash _.prototype.plant() 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 _.prototype.plant(value) method of Sequence in lodash is used to create a clone of the chain sequence type by planting the value to be planted as the wrapped value.

Syntax:

_.prototype.plant(value)

Parameters: This method accepts single parameter as mentioned above and described below:

  • value: It is the value that need to be planted.

Return Value: This method returns the new lodash wrapper instance.

Example 1:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Creating an addition function
function add(n) {
  return n + n;
}
  
// Creating wrapped value
var wrapper = _([4, 4]).map(add);
  
// Calling prototype.plant(value) method
var res = wrapper.plant([8, 8]);
   
// Displays output 
console.log(res.value());
wrapper.value();


Output:

[ 16, 16 ]
[ 8, 8 ]

Example 2:

Javascript




// Requiring lodash library
const _ = require('lodash');
  
// Creating a function
function fun(n) {
  return (n * 5);
}
  
// Calling prototype.plant(value) method
var obj = _().map(fun).plant({'f': 5, 'g': 7});
   
// Displays output 
console.log(obj.value());


Output:

[ 25, 35 ]

Here, the values are multiplied by 5 and then returned as output.

Reference: https://lodash.com/docs/4.17.15#prototype-plant

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

3 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS