1function getRandomString(length) {
2 var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
3 var result = '';
4 for ( var i = 0; i < length; i++ ) {
5 result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
6 }
7 return result;
8}
9var randString = getRandomString(20);//get rand alphanumberic 20 char string
10var randBase64String = btoa(randString); // Base64 encode the String
1var string = "Hello folks how are you doing today?";
2var encodedString = btoa(string); // Base64 encode the String
3var decodedString = atob(encodedString); // Base64 decode the String
4
1function getRandomString(length) {
2 var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
3 var result = '';
4 for ( var i = 0; i < length; i++ ) {
5 result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
6 }
7 return result;
8}
9
10//usage: getRandomString(20); // pass desired length of random string
1function makeid() {
2 var text = "";
3 var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
4
5 for (var i = 0; i < 5; i++)
6 text += possible.charAt(Math.floor(Math.random() * possible.length));
7
8 return text;
9}
10
11console.log(makeid());
12