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:

How to submit form using javascript or jquery.
16-04-2017 javascript jquery submit form
How to use request module in node js
16-03-2017 request module node js
Remove last two characters from given string
06-03-2017 substring javascript remove
Send Mail in Node Js
21-02-2017 node js mail npm module
Get Unique values from array/object in javascript
19-02-2017 javascript unique remove repeated values from array