Creates an object composed of the inverted keys and values of object. Part of Lodash Object (stable — not deprecated). If values collide, later keys overwrite earlier ones. To keep every original key under a shared value, use _.invertBy.
Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.
Syntax
Call _.invert. Start with this line.
Lodash
_.invert(object)
Call
What it does
_.invert(object)
Primary signature.
Prefer import invert from "lodash/invert" when you want a smaller bundle.
Library declarations
Lodash
_.invert(object)
Parameters
Parameter
Description
object
Required. Object to invert
Return Value
Return Value
Description
*
New inverted object
Lodash Examples
Example 1 — Official: Invert with Duplicate Values
Later keys overwrite earlier ones for the same value.
invertBy. Groups every original key into an array.
When. Unique values → invert.
When. Duplicates matter → invertBy.
Compatibility
Browser & Runtime Support
_.invert is a Lodash Object helper available in 4.x (and earlier builds). 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 assign result[value] = key.
✓ Stable · Lodash 4.x
_.invert()
Available in [email protected] full builds and the lodash/invert 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
_.invertLodash 4.x
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import invert from "lodash/invert" for smaller builds. Use invertBy when duplicate values must be preserved.
Frequently Asked Questions
_.invert(object) creates a new object composed of the inverted keys and values. Official: _.invert({ a: 1, b: 2, c: 1 }) → { '1': 'c', '2': 'b' }.
Subsequent values overwrite earlier ones. In the official example both a and c map to 1, so the inverted key '1' keeps the last key, 'c'.
No. It returns a new object. The original is left unchanged.
Values become keys, so they are coerced to strings. Numbers become '1', booleans become 'true', and plain objects become '[object Object]'.
Use _.invertBy when values are not unique and you want every original key kept in an array under that inverted value.
Use import invert from "lodash/invert" or require("lodash/invert") so bundlers can tree-shake. Full build: import _ from "lodash" then _.invert.