JavaScript method for generating random strings

  • 2020-05-17 04:46:25
  • OfStack

This example shows how JavaScript generates random strings. Share with you for your reference. The specific analysis is as follows:

Here, JavaScript is used to generate a random string. You can specify the length of the string.

function RandomString(length) {
    var str = '';
    for ( ; str.length < length; str += Math.random().toString(36).substr(2) );
    return str.substr(0, length);
}

I hope this article has been helpful to your javascript programming.


Related articles: