how to generate random alphanumeric string in javascript code example
Example 1: generate random alphanumeric string javascript
Math.random().toString(36).substr(2, 6);
Example 2: how to generate 6 random alphanumerals in js
let characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
let result = ''
let length = 10
for (let i = length; i > 0; --i) result += characters[Math.round(Math.random() * (characters.length - 1))]
console.log(result)
Example 3: 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)