_.stubObject is a Lodash Util helper since 4.13.0. It runs anywhere Lodash 4.13+ runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.13.0+
_.stubObject()
Available in [email protected] full builds and the lodash/stubObject modular import. Works in evergreen browsers and current Node LTS when Lodash ≥ 4.13 is installed.
100%With Lodash 4.13+
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
_.stubObjectLodash 4.13.0+
Bottom line: Safe for production once Lodash 4.13+ is loaded. Prefer import stubObject from "lodash/stubObject" for smaller bundles. Use it when you need a fresh empty object per call.
Frequently Asked Questions
_.stubObject() returns a new empty object {} every time. Official: _.times(2, _.stubObject) → [{}, {}] and objects[0] === objects[1] is false.
No. Each call allocates a fresh {}. Mutating one result does not change another.
_.constant({}) always returns the same object reference. stubObject returns a new {} per call — safer as a factory.
No. Arguments are ignored. _.stubObject({ a: 1 }) still returns a new empty object.
As a default-object factory, with _.times to build many empty buckets, or anywhere an API needs a fresh {} callback.
Use import stubObject from "lodash/stubObject" or require("lodash/stubObject"). Full build: import _ from "lodash" then _.stubObject.