JavaScript (ES2026) reference · String Methods
JavaScript String padEnd() Method
Pad the end of a string with another string until it reaches a target length. Useful for aligned text columns.
JavaScript (ES2026) Since ES2017
Syntax
string.padEnd(targetLength, padString)
Parameters
| Parameter | Description |
|---|---|
targetLength |
The length of the result. |
padString optional |
Text to pad with. Default: " " |
Return value
A new string.
Examples
for (const [item, price] of [["Tea", 3.5], ["Sandwich", 6]]) {
console.log(item.padEnd(10, ".") + price.toFixed(2));
}
Output
Tea.......3.50 Sandwich..6.00
console.log("abc".padEnd(2), "abc".padEnd(6, "12"));
Output
abc abc121
Version history
| Version | Change |
|---|---|
| JavaScript ES2017 | Added |
In other languages
str.ljust()· Pythonstr_pad()· PHPmb_str_pad()· PHP
Related
string.padStart()· Pad the start of a string until it reaches a target length, for example zero-padding numbers like 007.string.repeat()· Return a new string made of this string repeated a given number of times, for example to build separators or padding.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial