Search code examples
javascriptuuid

How can I generate a UUID v4 that starts with '00' using JavaScript?


How to generate a valid UUID v4 that starts with specific characters?

Suppose I want to generate UUID v4 that starts with 00 – short of looping through random UUIDs until I get UUID that starts with 00, is there a better way of doing it?


Solution

  • You can just remove the first two characters of a generated UUID and prepend "00" in its place.

    console.log('00' + crypto.randomUUID().slice(2));