By the end of this tutorial, you’ll use wrapper .chain() to switch into explicit chaining mode and keep methods like head() wrapped until you call .value().
01
Explicit mode
_(x).chain()
02
Hybrid vs explicit
When unwrap happens.
03
head + pick
Classic use case.
04
vs _.chain()
Entry vs mid-pipeline.
05
Pipeline steps
filter, map, take.
06
Unwrap
Finish with .value().
Fundamentals
What Is Wrapper .chain()?
Wrapper .chain() switches a Lodash wrapper from hybrid chaining to explicit chaining. After you call it, every subsequent method returns another wrapper until you unwrap with .value()—even methods like head() that would normally return a plain value immediately.
💡
Not _.prototype.chain() or entry-point _.chain()
There is no _.prototype.chain() function. Wrapper .chain() is called on an existing wrapper: _(users).chain().head().pick('user').value(). That is different from _.chain(value), which wraps a value to start a pipeline.
Use wrapper .chain() when hybrid mode would unwrap too early—for example, when you need head() followed by pick(), or any pipeline where an “exit” method should stay chainable.
Foundation
📝 Syntax
Call .chain() on a wrapper with no arguments:
javascript
_(value).chain()
// or mid-pipeline on an existing wrapper
_.chain(value).chain()
Syntax Rules
No arguments — .chain() takes nothing; it toggles explicit mode on the current wrapper.
Return — another Lodash wrapper in explicit chaining mode.
Hybrid default — without .chain(), some methods auto-unwrap (head, first, last, etc.).
Must unwrap — end with .value() to get plain JavaScript data.
Entry point alternative — _.chain(value) starts in explicit mode from the beginning.
Begin from _(value) or any existing Lodash wrapper in hybrid mode.
Input
2
Call .chain()
Lodash re-wraps the current value and enables explicit chaining—exit methods no longer auto-unwrap.
Explicit
3
Chain more methods
Call head, pick, filter, etc.—each returns another wrapper until unwrap.
Pipeline
=
⚡
Unwrap when done
.value() runs the pipeline and returns plain JavaScript data—same as any other Lodash chain.
Important
📝 Notes
There is no _.prototype.chain() function—the correct name is wrapper .chain() on a sequence object.
Wrapper .chain() is not the same as entry-point _.chain(value)—different purpose, same explicit mode.
Hybrid chaining (default with _(value)) auto-unwraps methods like head, first, last, and value.
If your entire pipeline needs explicit mode, start with _.chain(value) instead of adding .chain() after wrap.
Always end with .value() to get the final plain result in application code.
Next in the series: .commit() runs pending steps eagerly while keeping the wrapper.
Wrap Up
Conclusion
Wrapper .chain() switches a Lodash wrapper into explicit chaining mode so methods like head() stay wrapped and you can keep building the pipeline. It solves the hybrid unwrap problem—especially the classic head().pick() pattern.
Next in the wrapper prototype series: .commit(), which executes pending chain actions eagerly while returning the wrapper for more steps.
Use wrapper .chain() when hybrid mode unwraps before you are done chaining
Prefer _.chain(value) when the whole pipeline should be explicit
Extract helper functions for filter/map predicates in long pipelines
Keep pipelines readable—break very long chains into named steps
Always call .value() before passing results to non-Lodash code
❌ Don’t
Confuse wrapper .chain() with entry-point _.chain(value)
Call it _.prototype.chain()—that name does not exist in Lodash
Add redundant .chain() after _.chain(value)—already explicit
Chain excessively when two direct Lodash calls would be clearer
Forget that hybrid _(value).head() unwraps without .chain()
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about wrapper .chain()
Use these when hybrid chaining unwraps too early.
5
Core concepts
🔗01
Explicit mode
_(x).chain()
Core
🔄02
Hybrid default
Auto-unwraps.
Contrast
👤03
head + pick
Classic pattern.
Use case
🚀04
vs _.chain()
Mid vs start.
Compare
📦05
Always unwrap
.value() required.
Critical
❓ Frequently Asked Questions
On an existing Lodash wrapper, .chain() enables explicit chaining. Subsequent methods stay wrapped until you call .value(), even methods like head() that would normally unwrap in hybrid mode.
No. _.chain(value) is the entry-point that wraps a value to start a pipeline. Wrapper .chain() is called on an already-wrapped value to switch from hybrid to explicit chaining mid-pipeline.
When you want to call a method that would auto-unwrap (like head, first, last, tap in some cases) and then continue chaining more Lodash methods on the result.
In hybrid mode, _(users).head() unwraps immediately and returns a plain object—you cannot call .pick() on it. Add .chain() to keep head()'s result wrapped.
No. Call it with no arguments: _(value).chain(). It re-wraps the current value in explicit chaining mode.
Yes. Explicit chaining still returns a wrapper for each step until you unwrap with .value() or .valueOf().
Did you know?
Lodash has two chaining modes: hybrid (default with _(value)) and explicit (after wrapper .chain() or entry-point _.chain(value)). In hybrid mode, _(users).head() returns a plain object immediately—add .chain() first if you need to keep chaining.