JavaScript String.prototype.padEnd() Method
The padEnd() method pads the end of a string with another string until it reaches a given length.
Description
The padEnd() method adds characters to the end of a string until it reaches the target length. If the string is already that long, it is returned unchanged. It's useful for lining up text in fixed-width output.
If the pad string is longer than needed, it's cut off to fit, and if it's empty, the original string is returned unchanged. Lengths are measured in UTF-16 code units, so strings containing emoji or wide characters may not line up exactly in a monospace display.
Padding is mainly useful in the console, plain-text files and fixed-width data formats. On web pages, alignment is better handled with CSS, such as a table or a grid layout, which adapts to fonts and screen sizes.
Syntax
string.padEnd(targetLength)
string.padEnd(targetLength, padString)Parameters
- targetLengthThe length of the resulting string.
- padStringOptional. The text to pad with. Defaults to a space.
Return Value
The string padded at the end to the target length.
Example
Browser Support
The following information will show you the current browser support for the String.prototype.padEnd() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





