Create a unique number with javascript time

后端 未结 30 3117
生来不讨喜
生来不讨喜 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:47

    Easy and always get unique value :

    const uniqueValue = (new Date()).getTime() + Math.trunc(365 * Math.random());
    **OUTPUT LIKE THIS** : 1556782842762
    

提交回复
热议问题