docs.rodeo

MDN Web Docs mirror

Crypto: randomUUID() method

{{APIRef("Web Crypto API")}} {{SecureContext_header}} {{AvailableInWorkers}} 

The randomUUID() method of the {{domxref("Crypto")}}  interface is used to generate a v4 {{Glossary("UUID")}}  using a cryptographically secure random number generator.

Syntax

randomUUID()

Parameters

None.

Return value

A string containing a randomly generated, 36 character long v4 UUID.

Examples

/* Assuming that self.crypto.randomUUID() is available */

let uuid = self.crypto.randomUUID();
console.log(uuid); // for example "36b8f84d-df4e-4d49-b662-bcde71a8764f"

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN