If you’ve ever needed to generate unique identifiers in your web applications, window.crypto.randomUUID() is a method that generates a v4 UUID (Universally Unique Identifier).
It’s part of the Web Crypto API and is supported in all modern browsers.
Why Use It?
- Simplicity: No need for external libraries or complex algorithms.
- Security: It uses a cryptographically strong random number generator.
- Standards-compliant: Generates UUIDs according to RFC 4122.
Here’s how to use it:
const uuid = window.crypto.randomUUID();
console.log(uuid); // e.g. "36b8f84d-df4e-4d49-b662-bcde71a8764f"