Create a unique number with javascript time

后端 未结 30 3119
生来不讨喜
生来不讨喜 2020-12-02 08:31

I need to generate unique id numbers on the fly using javascript. In the past, I\'ve done this by creating a number using time. The number would be made up of the four digi

30条回答
  •  天命终不由人
    2020-12-02 08:53

    Always get unique Id in JS

    function getUniqueId(){
       return (new Date().getTime()).toString(36) + new Date().getUTCMilliseconds();
    }
    
    getUniqueId()    // Call the function
    
    ------------results like
    
    //"ka2high4264"
    
    //"ka2hj115905"
    
    //"ka2hj1my690"
    
    //"ka2hj23j287"
    
    //"ka2hj2jp869"
    

提交回复
热议问题