programming-examples/js/Functions/Write a JavaScript function that generates a string id (specified length) of random characters..js
2019-11-15 12:59:38 +01:00

11 lines
292 B
JavaScript

function makeid(l)
{
var text = "";
var char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i=0; i < l; i++ )
{
text += char_list.charAt(Math.floor(Math.random() * char_list.length));
}
return text;
}
console.log(makeid(8));