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:

Convert and download html to pdf without saving file

28-10-2018 node js convert html to pdf pdf download pdf without saving

Time Sorting Ascending or Descending Order in Javascript

19-07-2017 Javascript ascending order descending order

How to redirect one page to another page in php

20-03-2017 redirect php

How to use request module in node js

16-03-2017 request module node js

Get random strings from given string In javascript

21-02-2017 javascript random string