r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

Show parent comments

1

u/SuperFLEB Mar 19 '19

Anyone got anything for generating a random string of letters? I know you can use someNumber.toString(36) to get a string of letters and numbers, but I don't know how to get only letters.

3

u/inu-no-policemen Mar 19 '19
> String.fromCharCode(...Array.from({length: 12}, _ => Math.random() * 25 + 97 | 0))
"niapavvsjdfb"

1

u/qbbftw Mar 19 '19

randexp is good at generating random strings, though it may not be as fast as the String.fromCharCode method