How to create unique IDs with JavaScript?

Spread the love

To create unique IDs with JavaScript, we can use a timestamp.

For instance, we write

const uniq = "id" + new Date().getTime();

to create a new date object with the current time with the Date constructor.

And we get its Unix timestamp in milliseconds with getTime.

Leave a Reply

Your email address will not be published. Required fields are marked *