Get random strings from given string In javascript

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:

Simple Array Sum | Javascript | hackerrank.com

07-05-2020 hackerrank.com javascript arrays array sum

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

Filters for convert text to camel case in Angular Js

05-03-2017 angularjs camelcase filters

Email validation regular expression in javascript

22-02-2017 email validation regex

Get random strings from given string In javascript

21-02-2017 javascript random string