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:

How to search text in string using php ?

29-10-2017 php search string search

Convert Time 24 hrs to 12 hrs format In javascript

12-03-2017 date javascript 12hrs convert

How to convert html to pdf in Node js

12-03-2017 pdf convert html node js

Change datepicker display format

06-03-2017 datepicker angular js

Filter for insert HTML in Angular Js

06-03-2017 filter show html angular js html