Recipes
Data & Functions
Generate a UUID

Generate a UUID

Problem

You want to generate a random and unique id for use in your application.

Solution

Use the built-in $crypto.randomUUID() function to receive a string of a random UUID (opens in a new tab) v4.

For example in a TypeScript client function:

Code example

const myUUID = $crypto.randomUUID()
return myUUID // => f0914ce4-0701-4c6e-b704-3b96b3654eb7

Discussion

See also