Generate random string/characters in JavaScript

前端 未结 30 1792
闹比i
闹比i 2020-11-21 06:34

I want a 5 character string composed of characters picked randomly from the set [a-zA-Z0-9].

What\'s the best way to do this with JavaScript?

30条回答
  •  悲&欢浪女
    2020-11-21 07:30

    To meet requirement [a-zA-Z0-9] and length=5 use

    btoa(Math.random()).substr(10, 5);
    

    Lowercase letters, uppercase letters, and numbers will occur.

提交回复
热议问题