Generate Random String using JavaScript

1 min read

In this post, we will be writing a simple JavaScript function that will generate random string of desired length. We can generate a random string with fixed set of characters using simple match and string functions.

function generateRandomString(length){
    var chars = '[email protected]!#$%^&*()';
    var random_string = '';
    if(length > 0){
      for(var i=0; i < length; i++){
          random_string += chars.charAt(Math.floor(Math.random() * chars.length));
    return random_string;



Follow this video for complete guidance :

Recommended For You

About the Author: Admin