String.prototype.padEnd()

Pads the end of a string with another string until it reaches a target length.

Since ES2017 Spec ↗

Syntax

str.padEnd(targetLength, padString)

Parameters

NameTypeRequiredDescription
targetLength number Yes The desired final length. If less than the current length, the string is returned unchanged.
padString string No The string to pad with, repeated as needed and truncated. Defaults to a space.

Returns

string — A new string padded at the end to the target length.

Examples

console.log('5'.padEnd(3, '0'));
Output
500
console.log(('Name'.padEnd(8) + '|'));
Output
Name    |

Notes

Useful for aligning columns of text. The pad string is truncated if it would overflow the target length. Does not mutate the original string.

Browser & runtime support

EnvironmentSince version
chrome 57
firefox 48
safari 10
edge 15
node 8.0

See also