_.chain() wraps any value in a Lodash sequence object so you can call chainable Lodash methods one after another in a fluent, top-to-bottom pipeline. It is the explicit entry point for method chaining—the same role as the shorthand _(value).
💡
Wrapper, not result
After _.chain([1,2,3]).map(...) you still hold a wrapper. Call .value() to get the plain array, object, or number your pipeline produced.
Use it when three or more Lodash steps would otherwise nest inside each other, when you want pipeline-style readability, or when mixing Collection, Array, and Object helpers in one flow.
Foundation
📝 Syntax
The signature takes one argument—the value to wrap:
javascript
_.chain(value)
Syntax Rules
value — any value to wrap (array, object, number, etc.).
Return value — a Lodash wrapper; chainable methods return another wrapper.
Unwrap — call .value() or .valueOf() for the final result.
Chainable methods — most Lodash map/filter/pick-style helpers work on the wrapper.
Not lazy — steps run when you unwrap, not as an infinite stream.
javascript
import chain from "lodash/chain";
const data = [1, 2, 3, 4, 5];
const result = chain(data)
.map(function (x) { return x * 2; })
.filter(function (x) { return x > 5; })
.value();
// result -> [6, 8, 10]
_.chain(value) stores your array, object, or primitive inside a Lodash sequence wrapper.
Input
2
Queue chain steps
Each chained method (map, filter, pick, etc.) returns another wrapper with the next step recorded.
Pipeline
3
Execute on unwrap
Calling .value() runs all queued operations in order and returns plain JavaScript data.
Unwrap
=
🔗
Plain result
You get an array, object, or number—not a wrapper. Use _.tap() to inspect mid-chain without breaking the flow.
Important
📝 Notes
_.chain() returns a wrapper, not the transformed data—always call .value() (or .valueOf()) to finish.
_(value) is a shorthand alias for starting the same kind of sequence.
Chaining is about readability, not lazy infinite streams—steps run when you unwrap.
Some chain methods (like reverse) may mutate the wrapped value in place; check docs for each method.
For side effects between steps (logging, debugging), use _.tap(); to transform the wrapped value inline, use _.thru().
For one or two Lodash calls, nested plain calls are often simpler and tree-shake better in modern bundles.
Wrap Up
Conclusion
_.chain() turns a series of Lodash operations into a readable top-to-bottom pipeline. Wrap your data, chain the transforms you need, and unwrap with .value() to get a plain result. It shines when you have three or more sequential Lodash steps on the same value.
For the same behavior with shorter syntax, use _(value). Next in the series: the shorthand wrapper entry point and wrapper prototype helpers like .value().
End every chain with .value() before passing data to other code
Keep pipelines focused—extract very long chains into named functions
Use take, slice, or early filter to limit intermediate work
Prefer chaining when you have three or more Lodash steps on one value
Use _.tap() for debug logging without altering the pipeline result
❌ Don’t
Forget .value() and treat the wrapper like a plain array or object
Build chains so long they become hard to test or debug
Assume chaining is lazy streaming—unwrap still runs steps eagerly
Chain when a single _.map() or native .filter() is enough
Mix chain wrappers with plain Lodash calls without unwrapping first
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.chain()
Use these when building fluent Lodash pipelines.
5
Core concepts
🔗01
Wrap first
_.chain(value)
Core
🔀02
Fluent steps
map, filter, sort.
Pattern
📦03
Always unwrap
.value() required.
Critical
📈04
Readable flow
Top-to-bottom.
Style
🛠️05
Know when
3+ Lodash steps.
Guideline
❓ Frequently Asked Questions
_.chain(value) wraps a value in a Lodash sequence object so you can call chainable Lodash methods (map, filter, pick, etc.) in a fluent pipeline, then unwrap with .value().
Intermediate chain steps return a wrapper, not plain JavaScript data. .value() executes the pipeline and returns the final unwrapped result.
Both start a Lodash wrapper around a value. _.chain(value) is explicit; _(value) is the shorthand alias—they behave the same for beginning a sequence.
It depends on the methods you call in the chain. _.chain itself only wraps; map and filter return new data, while some methods like reverse may mutate in place.
Not in the general sense. The wrapper defers unwrapping until .value(), but when you unwrap, the steps run eagerly. It is not infinite lazy evaluation like a generator stream.
For one or two Lodash calls, nested plain calls or native array methods are often clearer and tree-shake better. Use chaining when you have three or more sequential Lodash steps.
Did you know?
_.chain() and _(value) start the same wrapper type—only the syntax differs. Lodash also supports implicit chaining on some methods when you use _(value) without an explicit _.chain() call, but explicit chaining makes the pipeline obvious in code reviews.