Get random strings from given string In javascript

21-02-2017 javascript random string

The below function return a random string with given length

function randomString(length) {
    chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
}
var res = randomString(4);
alert(res);

 

You might also like:

Remove last two characters from given string using slice
07-03-2017 slice remove
Get next date from given date in javascript
06-03-2017 date javascript next date
How to find Angular Errors
06-03-2017 errors angularjs exceptionHandler
Filter for insert HTML in Angular Js
06-03-2017 filter show html angular js html
Email validation regular expression in javascript
22-02-2017 email validation regex