Invokes interceptor with the object, then returns that same object (official Underscore docs). Built to “tap into” a method chain and act on intermediate results. Stable Object helper — not deprecated.
Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.
Syntax
Call _.tap. Start with this line.
Underscore
_.tap(object, interceptor)
Call
What it does
_.tap(object, interceptor)
Primary signature.
_.tap(...)
Call with the arguments your case needs.
Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.
Library declarations
Underscore
_.tap(object, interceptor)
Parameters
Parameter
Description
object
Required. Value to pass through and return
interceptor
Required. Function called once with that value
Return Value
Return Value
Description
*
Same object (interceptor return ignored)
Underscore.js Examples
Example 1 — Basic Tap
The interceptor sees the value; _.tap returns that same value.
Underscore
var notes = [];
var result = _.tap([1, 2, 3], function (arr) {
notes.push("saw " + arr.length + " items");
});
// notes → ["saw 3 items"]
// result → [1, 2, 3] (same array)
Tap next. Push a log line about the current array.
Unwrap..value() returns the mapped array unchanged.
Pattern. Side effect in the middle; data keeps flowing.
Compatibility
Browser & Runtime Support
_.tap ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.
✓ Stable · Underscore 1.x
_.tap()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.tapUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.tap(object, interceptor) calls interceptor(object), then returns the same object. Use it to peek or run a side effect without replacing the value in a chain.
Tapping into a method chain so you can inspect or act on an intermediate result, then let the chain continue with the same value. See the official filter → tap → map example on underscorejs.org.
No. _.tap always returns the exact object you passed in. Changes happen only if your interceptor mutates that object.
It is ignored. Even if the interceptor returns something else, _.tap still hands back the original object.
Call .tap(fn) between steps. The wrapped value is passed to fn; the chain keeps flowing with that same value until .value().
No. _.each loops each element. _.tap hands the whole value once to the interceptor and returns it — it does not iterate.