DEV Community

Katie Radford
Katie Radford

Posted on • Edited on

Quickest JS string generator

If you need a string of a certain length but don't care so much about the content, this one-line function is just what you are looking for!

const generateString = length => ''.padEnd(length, 'ABC123')
Enter fullscreen mode Exit fullscreen mode

And you can create strings of any length without directly pasting a huge string.

generateString(200)
'ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123AB'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)