generate unique string in javascript code example
Example 1: javascript generate random string
Math.random().toString(36).substring(2);
Example 2: javascript get random string
function getRandomString(length) {
var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var result = '';
for ( var i = 0; i < length; i++ ) {
result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
}
return result;
}
Example 3: random id js
var ID = function () {
return '_' + Math.random().toString(36).substr(2, 9);
};