Skip to content

Instantly share code, notes, and snippets.

@NullDev
Last active March 9, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NullDev/da83b28fd00463f3b86251eaf8d39c0c to your computer and use it in GitHub Desktop.
Save NullDev/da83b28fd00463f3b86251eaf8d39c0c to your computer and use it in GitHub Desktop.
ES6 way of generating a random string with variable length
let getRandomString = (length) => [...Array(length)].map(() => Math.random().toString(36)[2]).join("");
let str = getRandomString(10);
// -> 225n9b53x6
// ---
// Demo: https://jsfiddle.net/fku9y6sm/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment