How to generate unique ID with node.js

前端 未结 14 1852
感动是毒
感动是毒 2020-12-12 10:17
function generate(count) {
    var founded = false,
        _sym = \'abcdefghijklmnopqrstuvwxyz1234567890\',
        str = \'\';
    while(!founded) {
        for(va         


        
14条回答
  •  [愿得一人]
    2020-12-12 10:49

    Simple, time based, without dependencies:

    (new Date()).getTime().toString(36)
    

    Output: jzlatihl


    plus random number (Thanks to @Yaroslav Gaponov's answer)

    (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2)
    

    Output jzlavejjperpituute

提交回复
热议问题