Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lodash _.prototype.plant() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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


My Personal Notes arrow_drop_up
Last Updated : 18 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials