Categories
JavaScript Answers

How to create a unique number with JavaScript time?

Spread the love

Sometimes, we want to create a unique number with JavaScript time.

In this article, we’ll look at how to create a unique number with JavaScript time.

How to create a unique number with JavaScript time?

To create a unique number with JavaScript time, we can add the timestamp of the current datetime to a random number.

For instance, we write

const n = Date.now() + Math.random();

to add the timestamp of the current datetime that we get with Date.now to a random number returned by Math.random.

Conclusion

To create a unique number with JavaScript time, we can add the timestamp of the current datetime to a random number.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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