Snippet

Typescript Create Unique ID

AOAnonymous One· Sep 1, 20221 min read
  • #TypeScript
  • #Date

Typescript Create Unique ID

Math.round should be unique because of its seeding algorithm and also should be different because we are basing it off of Date.now() while converting this to a base 36 (numbers + letters)

const randomUniqueString = Math.floor(Math.random() * Date.now()).toString(36);
const id = `test-id-${randomUniqueString}`;

0 Comments

Sign in to join the conversation.

Search

Jump to a page, story or project