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:

Time Sorting Ascending or Descending Order in Javascript

19-07-2017 Javascript ascending order descending order

Remove last two characters from given string

06-03-2017 substring javascript remove

How to find Angular Errors

06-03-2017 errors angularjs exceptionHandler

Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js

05-03-2017 mm-dd-yyyy HH:MM date formats angular js

Filters for convert text to camel case in Angular Js

05-03-2017 angularjs camelcase filters