Learn all about the JavaScript padEnd() method for manipulating strings.

String padding involves adding characters to a string in order to achieve a specific length. Introduced in ES2017, the padEnd() method is used to append characters at the end of a string.

padEnd(targetLength [, padString])

Here is an example of how to use padEnd():

padEnd()
‘test’.padEnd(4) ‘test’
‘test’.padEnd(5) ‘test ’
‘test’.padEnd(8) ‘test    ’
‘test’.padEnd(8, ‘abcd’) ‘testabcd’

To explore a related method, check out padStart().