alphanumeric random generator javascript code example

Example 1: generate random alphanumeric string javascript

Math.random().toString(36).substr(2, 6); //6 is the length of the string

Example 2: how to generate 6 random alphanumerals in js

let characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
let result = ''
let length = 10 // Customize the length here.
for (let i = length; i > 0; --i) result += characters[Math.round(Math.random() * (characters.length - 1))]
console.log(result)