Lodash Wrapper .plant() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Seq & chaining

What You’ll Learn

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.

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.

📝 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]

⚡ Quick Reference

TaskCode patternResult
Replay map pipelinew.map(fn).plant(data)New wrapper
Unwrap planted chainw.plant(data).value()Plain array/object
Reuse filterw.filter(fn).plant(arr)Filtered new data
Original still workswrapped.value()Source pipeline result
Bulk unwrap.value()See .value()
Fresh chain instead_(data).map(fn)Rewrite transforms
Plant
.plant(value)

New data, same pipeline

Unwrap
.value()

Get plain result

Source
wrapped

Still independent

🧰 Parameters

Wrapper .plant(value) takes one argument and returns a new wrapper:

value Required

The new data to wrap. Lodash applies the existing queued chain actions to this value.

wrapped.plant([3, 4])
return Wrapper

A new Lodash wrapper—not plain JavaScript data. Chain further or call .value().

const other = wrapped.plant(data)
chain actions Copied

Transforms queued on the source wrapper (e.g. map, filter) are preserved on the planted wrapper.

_(a).map(fn).plant(b)
source wrapper Unchanged

The original wrapper is not mutated. You can still unwrap or plant from it again.

wrapped.value() // still works

For simple one-off transforms, rewriting _(data).map(fn) is fine—use .plant() when you want to reuse an existing pipeline object.

Examples Gallery

Practical wrapper .plant() patterns with sample output and interactive Try It Yourself labs.

📚 Getting Started

Build a transform pipeline, then .plant() new data onto the same queued actions.

Example 1 — Replay a map on different data

Square numbers from [1, 2], then plant [3, 4] to get squared results for the new array.

javascript
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]
Try It Yourself

How It Works

The map(square) step is queued on wrapped. .plant([3, 4]) creates a sibling wrapper that runs the same map on the new array.

Example 2 — Original wrapper stays independent

Planting does not consume or alter the source wrapper—both pipelines can be unwrapped separately.

javascript
const pipeline = _([10, 20]).map(function (n) {
  return n / 10;
});

const batchA = pipeline.plant([100, 200]);
const batchB = pipeline.plant([5, 15]);

console.log(batchA.value());
// -> [10, 20]

console.log(batchB.value());
// -> [0.5, 1.5]

console.log(pipeline.value());
// -> [1, 2]
Try It Yourself

📈 Practical Patterns

Reuse filters, extend planted chains, and compare with rewriting transforms.

Example 3 — Reuse a filter on two datasets

Keep evens from different arrays using one filter pipeline.

javascript
const evensOnly = _([1, 2, 3]).filter(function (n) {
  return n % 2 === 0;
});

const setA = evensOnly.plant([1, 2, 3, 4, 5]);
const setB = evensOnly.plant([6, 7, 8, 9, 10]);

console.log(setA.value());
// -> [2, 4]

console.log(setB.value());
// -> [6, 8, 10]
Try It Yourself

Example 4 — Plant, then keep chaining

Add more steps on the planted wrapper before unwrapping.

javascript
const doubled = _([1, 2, 3]).map(function (n) {
  return n * 2;
});

const result = doubled
  .plant([4, 5, 6])
  .take(2)
  .value();

console.log(result);
// -> [8, 10]

🚀 Beyond the Basics

Compare planting with starting fresh chains and know when each approach fits.

Example 5 — .plant() vs a fresh chain

Both approaches can produce identical output—plant shines when the pipeline object already exists.

javascript
function double(n) {
  return n * 2;
}

const pipeline = _([0]).map(double);
const viaPlant = pipeline.plant([1, 2, 3]).value();
const viaFresh = _([1, 2, 3]).map(double).value();

console.log(JSON.stringify(viaPlant) === JSON.stringify(viaFresh));
// -> true

Example 6 — When a helper function is clearer

Wrap a reusable pipeline in a function when you plant across many call sites.

javascript
function makeSquaredPipeline() {
  return _([0]).map(function (n) { return n * n; });
}

const squared = makeSquaredPipeline();

console.log(squared.plant([2, 3]).value());
// -> [4, 9]

console.log(squared.plant([5]).value());
// -> [25]

🧠 How Wrapper .plant() Works

1

Build a wrapper pipeline

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.

📝 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.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about wrapper .plant()

Use these when reusing Lodash chain pipelines on different inputs.

5
Core concepts
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.

Practice Wrapper .plant() in the Live Editor

Clone map and filter pipelines onto new arrays and compare results.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful