Open In App

Lodash _.prototype.plant() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

Lodash _.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:

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

Return Value:

This method returns the new lodash wrapper instance.

Example 1: In this example, we are getting new wrapper instances by using the lodash _.prototype.plant() method.

Javascript




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


Output:

[ 16, 16 ]
[ 8, 8 ]

Example 2: In this example, the values are multiplied by 5 and then returned as output.

Javascript




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


Output:

[ 25, 35 ]

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


Last Updated : 03 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads