how to generate random 5 digit alphanumeric in js 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: 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)