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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.padEnd(targetLength, padString)

Parameters

ParameterDescription
targetLength The length of the result.
padString optional Text to pad with. Default: " "

Return value

A new string.

Examples

Align columnsTry it yourself
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
Already long enough, or a multi-character padTry it yourself
console.log("abc".padEnd(2), "abc".padEnd(6, "12"));

Output

abc abc121

Version history

VersionChange
JavaScript ES2017Added

In other languages

Was this page helpful?