Like _.invert, except the inverted object is built from running each value through an optional iteratee. Part of Lodash Object (stable — not deprecated). Each inverted key maps to an array of source keys that produced it. The iteratee is invoked with one argument: (value).
Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.
Syntax
Call _.invertBy. Start with this line.
Lodash
_.invertBy(object, [iteratee])
Call
What it does
_.invertBy(object, [iteratee])
Primary signature.
_.invertBy(object)
Work with an object’s keys, values, or paths.
Prefer import invertBy from "lodash/invertBy" when you want a smaller bundle.
Library declarations
Lodash
_.invertBy(object, [iteratee])
Parameters
Parameter
Description
object
Required. Object to invert
iteratee
Optional. Invoked as (value) to build each bucket key
Why not invert? Duplicate statuses would drop ids.
Compatibility
Browser & Runtime Support
_.invertBy is a Lodash Object helper available in 4.x. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native equivalents loop own keys and push into bucket arrays.
✓ Stable · Lodash 4.x
_.invertBy()
Available in [email protected] full builds and the lodash/invertBy modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.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
_.invertByLodash 4.x
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import invertBy from "lodash/invertBy" for smaller builds. Use invert when you want a flat last-wins map.
Frequently Asked Questions
_.invertBy(object, [iteratee]) is like _.invert, but each inverted value is an array of source keys that produced it. Official: _.invertBy({ a: 1, b: 2, c: 1 }) → { '1': ['a', 'c'], '2': ['b'] }.
_.invert returns flat { value: key } pairs and drops earlier keys on collisions. _.invertBy keeps every key in an array bucket.
No. Without it, the original value becomes the bucket key. Pass an iteratee to derive bucket names — official docs use 'group' + value.
No. It returns a new object. The source is untouched.
Yes. Iteratee results are coerced to string keys, so object-typed results can collide as '[object Object]'.
Use import invertBy from "lodash/invertBy" or require("lodash/invertBy") so bundlers can tree-shake. Full build: import _ from "lodash" then _.invertBy.