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:

Functions in javascript

25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions.

How to upload file by using request module

18-03-2017 request module node js

Sanitization in java sript

14-03-2017 sanitization java script

Change datepicker display format

06-03-2017 datepicker angular js

Filters for convert text to camel case in Angular Js

05-03-2017 angularjs camelcase filters