By the end of this tutorial, you’ll use wrapper .plant(value) to replay an existing chain pipeline on new data without rebuilding the transforms.
01
Clone pipeline
.plant(value)
02
New wrapper
Independent result.
03
Reuse map
Same transform.
04
Reuse filter
Different inputs.
05
vs fresh chain
When to plant.
06
Keep chaining
Plant then extend.
Fundamentals
What Is Wrapper .plant()?
Wrapper .plant(value) creates a new Lodash wrapper that keeps the same queued chain actions—such as map, filter, or take—but starts from a different wrapped value. Think of it as copying a pipeline template onto fresh data.
💡
Not _.prototype.plant()
There is no _.prototype.plant() function. Call .plant(value) on a wrapper: _( [1, 2] ).map(square).plant([3, 4]) returns a new wrapper ready for .value().
The original wrapper is untouched. After planting, you can unwrap with .value() or keep chaining on the new wrapper. This is especially handy when you built a reusable transform once and need to apply it to multiple datasets.
Foundation
📝 Syntax
Pass the new starting value to .plant() on an existing wrapper:
javascript
const wrapped = _([1, 2]).map(function (n) { return n * n; });
const other = wrapped.plant([3, 4]);
// other is a new wrapper with the same map step
Syntax Rules
One argument — the new value to wrap (array, object, or other data).
Returns a wrapper — not plain data; call .value() to unwrap.
Preserves chain actions — queued transforms from the source wrapper are replayed on the new value.
Original unchanged — the source wrapper and its data stay independent.
Chain after plant — you can add more steps on the planted wrapper before unwrapping.
javascript
import _ from "lodash";
function square(n) {
return n * n;
}
const wrapped = _([1, 2]).map(square);
const other = wrapped.plant([3, 4]);
console.log(other.value());
// -> [9, 16]
console.log(wrapped.value());
// -> [1, 4]
Start with _(data) and queue transforms like map, filter, or take.
Pipeline
2
Call .plant(newValue)
Lodash clones the queued actions onto a new wrapper that wraps newValue.
Branch
3
Chain or unwrap
Add more steps on the planted wrapper or call .value() for the final result.
Result
=
⚡
Source stays intact
The original wrapper can still be planted again or unwrapped on its own data.
Important
📝 Notes
There is no _.prototype.plant() function—the correct name is wrapper .plant(value) on a sequence object.
.plant() returns a wrapper, not plain data—call .value() when you need the final array or object.
The source wrapper is not mutated; planted wrappers are siblings that share the same queued actions.
You can call .plant() multiple times from one pipeline to process different inputs in parallel.
For a single transform on one dataset, rewriting _(data).map(fn) is often simpler than planting.
Next in the series: .reverse() mutates the wrapped array in place.
Wrap Up
Conclusion
Wrapper .plant(value) lets you replay an existing Lodash chain on new data without rebuilding transforms. It returns a new independent wrapper, so you can branch pipelines, reuse filters and maps, and unwrap each result separately.
Next in the wrapper prototype series: .reverse(), which reverses the wrapped array in place.
Use .plant() when you already built a pipeline and need the same transforms on new data
Call .value() on the planted wrapper to get plain results for your app
Keep the source wrapper as a reusable template for multiple inputs
Wrap pipeline creation in a helper when you plant from many places
Verify independence—unwrap both source and planted wrappers to confirm expected output
❌ Don’t
Call it _.prototype.plant()—that name does not exist in Lodash
Expect .plant() to return plain data—it always returns a wrapper
Assume the source wrapper is consumed after planting—it remains usable
Use .plant() for trivial one-liner chains when a fresh _(data).map() reads clearer
Forget that planted wrappers can accept further chain steps before unwrapping
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about wrapper .plant()
Use these when reusing Lodash chain pipelines on different inputs.
5
Core concepts
🔄01
Clone pipeline
.plant(value)
Core
✅02
New wrapper
Source unchanged.
Critical
📈03
Reuse transforms
map, filter, etc.
Pattern
📦04
Then .value()
Unwrap result.
Compare
🛠️05
When to use
Template chains.
Guideline
❓ Frequently Asked Questions
It creates a new wrapper with the same queued chain actions (map, filter, etc.) but a different starting value. You reuse the pipeline template on fresh data.
No. plant() returns a new wrapper. The original wrapper and its underlying value remain independent.
A single value—the new data to wrap. Lodash applies the existing chain actions to that value when you unwrap or continue chaining.
No. It returns another wrapper. Call .value() (or keep chaining) on the planted wrapper to get plain JavaScript data.
Both can produce the same result. plant() is useful when you already built a transform pipeline and want to replay it on different inputs without rewriting the chain.
No. The correct API is wrapper .plant(value) on the object returned by _(value) or _.chain(value).
Did you know?
The name plant suggests grafting the same chain onto new “root” data—like planting a prepared pipeline into a different dataset while keeping the transform steps intact.