How to generate random alphanumeric strings in Javascript?
javascript function to generate random alphanumeric string
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
var result = ""
var charactersLength = characters.length;
for ( var i = 0; i < 5 ; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
console.log(result)
generate random alphanumeric string javascript
Math.random().toString(36).substr(2, 6); //6 is the length of the string
In the above example, the Math. random() method is used to generate random characters from the specified characters (A-Z, a-z, 0-9). The for loop is used to loop through the number passed into the generateString() function. During each iteration, a random character is generated.