Lodash _.thru() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Seq

Definition

Like _.tap, except it returns the result of interceptor. Use it to “pass thru” and replace intermediate values in a chain. Part of Lodash Seq (since 3.0.0).

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

Syntax

Call _.thru. Start with this line.

Lodash
_.thru(value, interceptor)
CallWhat it does
_.thru(value, interceptor)Primary signature.
_.thru(value)Wrap or control a Lodash sequence.

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

Library declarations
Lodash
_.thru(value, interceptor)

Parameters

ParameterDescription
valueRequired. Passed to the interceptor
interceptorRequired. Called as interceptor(value); its return becomes the result

Return Value

Return ValueDescription
*Whatever the interceptor returns

Lodash Examples

Example 1 — Official Trim → Array

Replace a trimmed string with a one-element array.

Lodash
_("  abc  ")
  .chain()
  .trim()
  .thru(function (value) {
    return [value];
  })
  .value();
// → ["abc"]
Try It Yourself

How It Works

  1. Chain. Explicit chaining keeps each step wrapped.
  2. Trim. " abc " → "abc".
  3. Thru. Returns ["abc"] — that becomes the new value.
  4. Docs. Matches the official Lodash example.

Example 2 — thru vs tap

Same interceptor; different return rules.

Lodash
[
  _.thru([1, 2], function (a) { return a.concat(99); }),
  _.tap([1, 2], function (a) { return a.concat(99); })
];
// → [[1, 2, 99], [1, 2]]
Try It Yourself

How It Works

  1. thru. Uses the interceptor return → [1, 2, 99].
  2. tap. Ignores the return → still [1, 2].
  3. Rule. Replace value → thru; side effect only → tap.
  4. Docs. Official: thru is like tap except it returns the interceptor result.

Example 3 — Custom Number Step

Insert a transform Lodash does not name as a chain method.

Lodash
_(10)
  .chain()
  .thru(function (n) { return n * 3 + 1; })
  .thru(function (n) { return "n=" + n; })
  .value();
// → "n=31"
Try It Yourself

How It Works

  1. First thru. 10 * 3 + 1 → 31.
  2. Second thru. Turns the number into "n=31".
  3. Value. Unwraps the final string.
  4. Use. Good for ad-hoc math or formatting mid-chain.

Example 4 — Standalone _.thru

Works outside a chain as a simple pass-thru call.

Lodash
_.thru("hi", function (s) {
  return s.toUpperCase();
});
// → "HI"
Try It Yourself

How It Works

  1. Call. _.thru("hi", fn) runs fn("hi").
  2. Return. Uppercased string becomes the result.
  3. No chain. Same function body as a chained .thru.
  4. Tip. Prefer named helpers when the transform is reused often.

Example 5 — Conditional Replace

Branch inside thru and return different shapes.

Lodash
function wrapOdds(n) {
  return n % 2 ? { odd: n } : { even: n };
}

_([1, 2, 3])
  .chain()
  .map(wrapOdds)
  .thru(function (list) {
    return list.filter(function (item) { return item.odd; });
  })
  .value();
// → [{ odd: 1 }, { odd: 3 }]
Try It Yourself

How It Works

  1. Map. Tag each number as odd/even objects.
  2. Thru. Filter to objects that have odd.
  3. Return. That filtered array replaces the previous list.
  4. Note. You could use .filter directly here; thru shines for less standard shapes.

Browser & Runtime Support

_.thru is a Lodash Seq method (since 3.0.0). It needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 3.0.0+

_.thru()

Available in [email protected] full builds and modular builds that include Seq helpers. Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.

100% With Lodash 3.0.0+
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
_.thru Lodash 3.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer the full lodash build for Seq chaining.

Frequently Asked Questions

_.thru(value, interceptor) returns the result of interceptor(value). Official docs: like _.tap except it returns the interceptor result, replacing intermediate chain values.
_(' abc ').chain().trim().thru(value => [value]).value() → ['abc']. Trim first, then wrap the string in an array.
tap always returns the original value (interceptor return ignored). thru returns whatever the interceptor returns.
When you need a custom transform that Lodash does not provide as a chain method — for example wrapping a string in an array mid-pipeline.
Yes. _.thru(value, fn) works standalone and simply returns fn(value).
The official example uses .chain() so later steps stay wrapped. In hybrid mode, some returns may unwrap early — use .chain() when you need explicit chaining.

Next: Lodash String

Explore Lodash string helpers like trim, camelCase, and more.

String hub →

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.

6 people found this page helpful