Lodash _.tap() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Seq

Definition

Invokes interceptor and returns value. Use it to “tap into” a method chain for side effects or intermediate mutations. Part of Lodash Seq (since 0.1.0).

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

Syntax

Call _.tap. Start with this line.

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

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

Library declarations
Lodash
_.tap(value, interceptor)

Parameters

ParameterDescription
valueRequired. Passed to the interceptor; also returned
interceptorRequired. Called as interceptor(value)

Return Value

Return ValueDescription
*Always the original value

Lodash Examples

Example 1 — Official Pop + Reverse

Mutate mid-chain, then reverse.

Lodash
_([1, 2, 3])
  .tap(function (array) {
    array.pop();
  })
  .reverse()
  .value();
// → [2, 1]
Try It Yourself

How It Works

  1. Start. Wrap [1, 2, 3].
  2. Tap. pop() removes 3 → [1, 2].
  3. Reverse. Order becomes [2, 1].
  4. Docs. Matches the official Lodash example.

Example 2 — Log Without Changing

Inspect an intermediate value; pipeline stays the same.

Lodash
var seen = null;

_([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. Double each number → [2, 4, 6].
  2. Tap. Snapshot that array into seen.
  3. Filter. Keep values > 2 → [4, 6].
  4. Point. Tap’s return was ignored; the mapped array continued.

Example 3 — tap vs thru

Same interceptor shape; different return rules.

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

How It Works

  1. tap. Runs the function, returns original [1, 2].
  2. thru. Returns the interceptor result [1, 2, 99].
  3. Rule. Side effect / mutate in place → tap; replace value → thru.
  4. Docs. Official thru is “like tap except it returns the result of interceptor.”

Example 4 — Standalone _.tap

Works outside a chain too.

Lodash
var logged = false;

var result = _.tap(42, function (n) {
  logged = n === 42;
});

[result, logged];
// → [42, true]
Try It Yourself

How It Works

  1. Call. _.tap(42, fn) invokes fn(42).
  2. Side effect. Sets logged to true.
  3. Return. Still 42.
  4. Use. Handy for small debug hooks without chaining.

Example 5 — Mutate, Then Map

Change the array in tap, then transform it.

Lodash
_([1, 2, 3])
  .tap(function (array) {
    array.push(4);
  })
  .map(function (n) { return n * 10; })
  .value();
// → [10, 20, 30, 40]
Try It Yourself

How It Works

  1. Tap. push(4) → array is [1, 2, 3, 4].
  2. Same ref. Chain continues with that mutated array.
  3. Map. Multiply each by 10.
  4. Result. [10, 20, 30, 40].

Browser & Runtime Support

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

✓ Stable · Lodash 0.1.0+

_.tap()

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
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
_.tap Lodash 0.1.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

_.tap(value, interceptor) invokes interceptor(value) for side effects, then returns value. Official docs: tap into a chain to modify intermediate results (often by mutation).
No. Lodash always returns the original value. Use _.thru() if you want the interceptor’s return to become the next chain value.
_([1,2,3]).tap(array => array.pop()).reverse().value() → [2, 1]. The tap pops 3, then reverse yields [2, 1].
tap returns the original value; thru returns whatever the interceptor returns.
Yes. _.tap(value, fn) works standalone — it still calls fn(value) and returns value.
Logging, debugging, metrics, or mutating intermediate data inside a chain without replacing the piped value via return.

Next: _.thru()

Replace intermediate chain values with the interceptor’s return.

_.thru() 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.

7 people found this page helpful