Generate UUID / Unique ID
Generate UUID / Unique ID is a reusable JavaScript snippet. Generates unique identifiers. Includes a simple UUID v4 generator and a shorter unique ID for non-critical use. The full implementation: // UUID v4 function uuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { const r = Math.random() * 16 | 0 return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16) }) } // Short unique ID (8 chars) function shortId(length = 8) { const chars = 'abcdefghijklmnopqrstuvwxyz0123456789' let result = '' for (let i = 0; i < length; i++) { result += chars.charAt(Math.floor(Math.random() * chars.length)) } return result } // Nano ID style (custom alphabet) function nanoId(size =… This snippet uses only standard JavaScript with no dependencies, so it runs in modern browsers and Node.js alike. Browse more patterns in the snippet library, or paste the code straight into the playground to experiment with it.