Lodash .chain() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Seq

Definition

Enables explicit method chaining on an existing Lodash wrapper (from _(value)). Methods that would auto-unwrap in hybrid mode (like head) stay wrapped until .value(). Part of Lodash 4.x Seq / wrapper prototype.

Call it on a Lodash wrapper. Finish with .value() when you need a plain result.

Syntax

Call .chain(). Start with this line.

Lodash
_(value).chain()…value()
CallWhat it does
_(value).chain()…value()Primary signature.

Prefer import _ from "lodash" (full build) when you need wrapper prototype helpers.

Library declarations
Lodash
_(value).chain()…value()

Parameters

ParameterDescription
WrapperRequired. From _(value)
.value()Required. Plain JavaScript result

Return Value

Return ValueDescription
*The value returned by .chain().

Lodash Examples

Example 1 — Official: head then pick

Explicit mode lets head stay wrapped so pick works.

Lodash
var users = [
  { user: "barney", age: 36 },
  { user: "fred", age: 40 }
];

_(users)
  .chain()
  .head()
  .pick("user")
  .value();
// → { user: "barney" }
Try It Yourself

How It Works

  1. Wrap. _(users) starts hybrid.
  2. chain. Switches to explicit mode.
  3. head. First user stays wrapped (not plain).
  4. pick + value. Keeps user, then unwraps.

Example 2 — Without .chain()

Hybrid head ends the sequence early.

Lodash
var users = [
  { user: "barney", age: 36 },
  { user: "fred", age: 40 }
];

_(users).head();
// → { user: "barney", age: 36 }   // plain object

_(users).chain().head().pick("user").value();
// → { user: "barney" }
Try It Yourself

How It Works

  1. Hybrid. Single-value head auto-unwraps.
  2. No pick. You cannot call .pick on a plain object.
  3. Explicit. .chain() keeps head wrapped.
  4. Official. Same contrast as the Lodash docs.

Example 3 — Explicit filter + map

A short pipeline that stays explicit end-to-end.

Lodash
var users = [
  { name: "Alice", age: 28 },
  { name: "Bob", age: 17 },
  { name: "Carol", age: 35 }
];

_(users)
  .chain()
  .filter(function (u) { return u.age >= 18; })
  .map("name")
  .value();
// → ["Alice", "Carol"]
Try It Yourself

How It Works

  1. chain. Explicit from the start of this pipeline.
  2. filter. Adults only — still wrapped.
  3. map. Pulls name — still wrapped.
  4. value. Plain name array.

Example 4 — vs _.chain()

Same result; different entry point.

Lodash
var users = [
  { user: "barney", age: 36 },
  { user: "fred", age: 40 }
];

var mid = _(users).chain().head().pick("user").value();
var start = _.chain(users).head().pick("user").value();

JSON.stringify(mid) === JSON.stringify(start);
// → true
Try It Yourself

How It Works

  1. Wrapper. _(v).chain() toggles explicit mid-wrap.
  2. Entry. _.chain(v) starts explicit.
  3. Same. Both need .value() at the end.
  4. Choose. Prefer entry _.chain if the whole pipeline is explicit.

Example 5 — Still wrapped after head?

Check that explicit head returns a wrapper.

Lodash
var users = [
  { user: "barney", age: 36 },
  { user: "fred", age: 40 }
];

typeof _(users).head();
// → "object"   // plain user

typeof _(users).chain().head().value;
// → "function" // still a Lodash wrapper
Try It Yourself

How It Works

  1. Hybrid head. Plain object — typeof "object".
  2. Explicit head. Wrapper still has .value.
  3. Proof. typeof …value is "function" before unwrap.
  4. Lesson. Call .value() when you need plain data.

Browser & Runtime Support

Wrapper .chain() ships with Lodash 4.x Seq. It runs anywhere full Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Modular lodash/* imports typically omit wrapper chaining.

✓ Stable · Lodash 4.x

Wrapper .chain()

Available on wrappers from _(value) in [email protected] full builds. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
wrapper.chain Lodash 4.x full

Bottom line: Safe for production with full Lodash. Use when hybrid auto-unwrap would break the next step; otherwise prefer _(v) or _.chain(v).

Frequently Asked Questions

It enables explicit chaining on an existing Lodash wrapper. Later methods stay wrapped until .value(), even methods like head() that auto-unwrap in hybrid mode.
No. _.chain(value) starts a pipeline already in explicit mode. Wrapper .chain() switches an existing _(value) wrapper from hybrid to explicit mid-pipeline.
When you want to call a single-value method (head, first, last, …) and then keep chaining (e.g. .pick()).
_(users).head() returns a plain object — you cannot call .pick() on it.
No. Call _(value).chain() with no arguments.
Yes. Explicit chains stay wrapped until .value() or .valueOf().

Next: .commit()

Run pending chain actions eagerly while keeping the wrapper.

.commit() →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful