Note. Pass a function — not _.uniqueId alone — so the prefix is applied each time.
Compatibility
Browser & Runtime Support
_.uniqueId is a Lodash Util helper since 0.1.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 0.1.0+
_.uniqueId()
Available in [email protected] full builds and the lodash/uniqueId modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 0.1+
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
_.uniqueIdLodash 0.1.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import uniqueId from "lodash/uniqueId" for smaller bundles. Use it for temporary local IDs; use UUID APIs for global uniqueness.
Frequently Asked Questions
_.uniqueId([prefix]) generates a unique string ID. If prefix is given, the incrementing number is appended to it. Official style: _.uniqueId('contact_') → 'contact_1' on a fresh counter.
No. With no arguments you get "1", "2", "3", … as strings. With a prefix like "user_" you get "user_1", "user_2", and so on.
No. Lodash uses one shared counter for all _.uniqueId calls in the process. After "a_1", the next _.uniqueId("b_") is "b_2", not "b_1".
The counter resets when the runtime reloads. IDs are unique only within the current JavaScript process—not across tabs, servers, or sessions.
No. It is for lightweight in-memory or DOM labels. Prefer database IDs, UUID, or another server-generated value for persisted records.
Use import uniqueId from "lodash/uniqueId" or require("lodash/uniqueId"). Full build: import _ from "lodash" then _.uniqueId.