DEV Community

Katie Radford
Katie Radford

Posted on • Updated 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

Oldest comments (0)