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
const _ = require( 'lodash' );
function add(n) {
return n + n;
}
let wrapper = _([4, 4]).map(add);
let res = wrapper.plant([8, 8]);
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
const _ = require( 'lodash' );
function fun(n) {
return (n * 5);
}
let obj = _().map(fun).plant({ 'f' : 5, 'g' : 7 });
console.log(obj.value());
|
Output:
[ 25, 35 ]
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,
GeeksforGeeks 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!
Last Updated :
03 Nov, 2023
Like Article
Save Article