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.