Code for generating Unique ID Using timestamp

We can generate unique IDs using the following Java script code. We can use this code for requirement which needs a unique value to be generated every time or when a conditions satifies.

And there are Random ID generating code are available but here we are using current date and time values to generate unique ID so it will be unique at most of the cases, less chances for duplication.

Code snippet:

var uniqueID = (Math.floor(Math.random() * Date.now()).toString(16)).toUpperCase();
console.log("uniqueID", uniqueID)

Leave a comment

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