transformation

String.prototype.padEnd

Returns a new string padded on the right with padString (default ' ') until it reaches targetLength. Added in ES2017.

str.padEnd(targetLength[, padString])

Parameters

Parameter Purpose
targetLength Desired final length in UTF-16 code units
padString String to pad with (default ' ')

Examples

console.log('5'.padEnd(3, '0'));

Prints '500'

console.log('hi'.padEnd(6));

Prints 'hi '

console.log('hello'.padEnd(3, '.'));

Prints 'hello' (already long enough)

console.log('a'.padEnd(5, 'xy'));

Prints 'axyxy'

Gotcha

Length is measured in UTF-16 code units — a single emoji counts as 2. Padding truncates, not repeats-and-cuts-from-end, to fit.

Related methods

← All JS string methods · JS array methods