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:

Example for Conditional Operator in php
16-04-2017 php Conditional Operator example
How to use http-post request in node js
14-03-2017 http-post module node js
How to get drop down value when drop down change using javascript
27-02-2017 onchange events dropdown javascript functions
How to remove last / value from url in javascript
27-02-2017 array javascript last value
Send Mail in Node Js
21-02-2017 node js mail npm module