Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

随机字符串 #19

Open
xxxgitone opened this issue Sep 4, 2017 · 0 comments
Open

随机字符串 #19

xxxgitone opened this issue Sep 4, 2017 · 0 comments

Comments

@xxxgitone
Copy link
Owner

之前做随机字符串的获取,都是先定义好一些字符串,然后在其中随机获取一些拼接起来,这样有些麻烦。今天学到一种新的获取方式

Math.random().toString(36) // "0.p1y8abl3of"

// 所以可以进行截取, 比如截取长度为5的
Math.random().toString(36).substr(2, 5) // "a0jzl"

// 如果不想包含数字,可以写正则表达式
Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5) // "iggav"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant