Creates a function that iterates over pairs and invokes the corresponding function of the first predicate to return truthy. Part of Lodash Util since 4.0.0 (stable — not deprecated).
Note: Predicates and handlers receive the same this binding and arguments as the created function.
Syntax
Call _.cond. Start with this line.
Lodash
_.cond(pairs)
Call
What it does
_.cond(pairs)
Primary signature.
_.cond(...)
Call the util helper.
Prefer import cond from "lodash/cond" when you want a smaller bundle.
_.cond is a Lodash Util helper since 4.0.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.0.0+
_.cond()
Available in [email protected] full builds and the lodash/cond modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.0+
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
_.condLodash 4.0.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import cond from "lodash/cond" for smaller bundles. Pair with matches, conforms, constant, and stubTrue for clear tables of rules.
Frequently Asked Questions
_.cond(pairs) returns a function that runs each [predicate, handler] pair in order and invokes the handler of the first truthy predicate. Official example returns 'matches A', 'matches B', or 'no match'.
Both receive the same this binding and arguments passed to the created function. If you call func(obj), every predicate and the chosen handler see obj.
_.stubTrue always returns true, so it acts as a default branch—like else or switch default. Without a match, the cond function returns undefined.
Yes. Lodash stops at the first truthy predicate. Put specific rules before general ones.
switch compares one value to case labels. _.cond runs arbitrary predicates—ranges, type checks, object shapes—in a reusable function.
Use import cond from "lodash/cond" or require("lodash/cond"). Full build: import _ from "lodash" then _.cond.