📜  生成随机 base 64 字符串 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:57.997000             🧑  作者: Mango

代码示例3
function getRandomString(length) {
    var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var result = '';
    for ( var i = 0; i < length; i++ ) {
        result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
    }
    return result;
}
var randString = getRandomString(20);//get rand alphanumberic 20 char string
var randBase64String = btoa(randString); // Base64 encode the String