OneCompiler

[Javascript] How can I generate random strings of given length?

I want to generate random strings of desired length. How do to that in Javascript?

1 Answer

4 years ago by

You can create a random string of desired length as shown below:

let strLength = 10;
console.log(Math.random().toString(20).substr(2, strLength));

Run here https://onecompiler.com/javascript/3xns846n4

4 years ago by Meera