Last active
March 9, 2020 15:39
-
-
Save NullDev/da83b28fd00463f3b86251eaf8d39c0c to your computer and use it in GitHub Desktop.
ES6 way of generating a random string with variable length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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