Lodash _.chain() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Seq

Definition

Creates a Lodash wrapper around value with explicit method chain sequences enabled. Finish with .value() to unwrap the result. Part of Lodash 4.x Seq.

Pass the value you want to wrap or transform. Finish with .value() when the result stays wrapped.

Syntax

Call _.chain. Start with this line.

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

Prefer import chain from "lodash/chain" when you want a smaller bundle.

Library declarations
Lodash
_.chain(value)

Parameters

ParameterDescription
valueRequired. Value to wrap

Return Value

Return ValueDescription
*Lodash wrapper (explicit chain)

Lodash Examples

Example 1 — Official Users Pipeline

Sort by age, map labels, take the youngest.

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

var youngest = _.chain(users)
  .sortBy("age")
  .map(function (o) {
    return o.user + " is " + o.age;
  })
  .head()
  .value();

// → "pebbles is 1"
Try It Yourself

How It Works

  1. Wrap. _.chain(users) starts an explicit sequence.
  2. sortBy. Orders by age ascending.
  3. map / head. Build labels, keep the first.
  4. value. Unwraps to the string "pebbles is 1".

Example 2 — map + filter Pipeline

A short numeric chain.

Lodash
_.chain([1, 2, 3, 4])
  .map(function (n) { return n * 2; })
  .filter(function (n) { return n > 5; })
  .value();
// → [6, 8]
Try It Yourself

How It Works

  1. map. Doubles each number → [2, 4, 6, 8].
  2. filter. Keeps values > 5.
  3. value. Returns a plain array.
  4. Pattern. Typical multi-step transform.

Example 3 — Forgetting .value()

Without unwrap, you still hold a Lodash wrapper.

Lodash
var wrapped = _.chain([1, 2, 3]).map(function (n) {
  return n * 10;
});

Array.isArray(wrapped);
// → false

Array.isArray(wrapped.value());
// → true

wrapped.value();
// → [10, 20, 30]
Try It Yourself

How It Works

  1. Chain. Intermediate results stay wrapped.
  2. Check. Array.isArray(wrapped) is false.
  3. Unwrap. .value() yields the real array.
  4. Habit. Always finish explicit chains with .value().

Example 4 — Explicit vs Implicit Wrap

_.chain stays wrapped; _(…) may auto-unwrap.

Lodash
_.chain([1, 2, 3]).head();
// → Lodash wrapper (still need .value())

_.chain([1, 2, 3]).head().value();
// → 1

_([1, 2, 3]).head();
// → 1   // implicit unwrap for this method
Try It Yourself

How It Works

  1. Explicit. _.chain keeps wrapping after head.
  2. value. Required to get 1.
  3. Implicit. _([1,2,3]).head() returns 1 directly.
  4. Rule. Prefer _.chain when every step must stay chainable.

Example 5 — Inspect Mid-Chain with tap

Side-effect without changing the pipeline value.

Lodash
var seen = null;

_.chain([1, 2, 3])
  .map(function (n) { return n * 2; })
  .tap(function (arr) { seen = arr.slice(); })
  .filter(function (n) { return n > 2; })
  .value();
// → [4, 6]

seen;
// → [2, 4, 6]
Try It Yourself

How It Works

  1. map. Doubles → [2, 4, 6].
  2. tap. Snapshot for debugging; value passes through.
  3. filter. Continues with the same array.
  4. More. See _.tap and _.thru.

Browser & Runtime Support

_.chain is a Lodash 4.x Seq helper. It runs anywhere full Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. There is no native fluent Lodash chain — use nested calls or array methods instead.

✓ Stable · Lodash 4.x

_.chain()

Available in [email protected] full builds. Wrapper chaining is not typical of tiny modular lodash/* imports. 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
_.chain Lodash 4.x full

Bottom line: Safe for production with full Lodash. Prefer _(value) for shorthand wraps, and .value() to finish every explicit chain.

Frequently Asked Questions

It wraps value in a Lodash wrapper with explicit method chaining enabled. You call Lodash methods fluently, then unwrap with .value().
Explicit chains keep returning a wrapper. .value() (alias .valueOf()) executes the sequence and returns the plain result.
_(value) uses implicit chaining — some methods that return primitives auto-unwrap. _.chain(value) is always explicit until .value().
Wrapping alone does not. Mutation depends on later methods (e.g. reverse may mutate; map/filter usually do not).
The wrapper defers unwrapping until .value(), but steps still run eagerly when you unwrap — not an infinite lazy stream.
For one or two calls, nested Lodash or native methods are often clearer and easier to tree-shake. Use chain for longer pipelines.

Next: _(value)

Start a Lodash sequence with the shorthand wrapper.

_(value) tutorial →

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