JavaScript: String.prototype.padEnd

By Xah Lee. Date: . Last updated: .

New in JS2017.

str.padEnd(n)
Return a new string, by adding space to the end of string so the length is n.
str.padEnd(n, padstr)
Use padStr to pad.
console.log( "x".padEnd(3) === "x  ");
console.log( "x".padEnd(3, "0") === "x00");
console.log( "x".padEnd(4, "ab") === "xaba");
// true

Note, when the string contains NON-ASCII character, result may not be expected.

[see Character, Code Unit, Codepoint]

console.log( "😂".padEnd(2,"x") === "😂" );
// no padding happens, because "😂" is already length 2

// 😂
// name: FACE WITH TEARS OF JOY
// codepoint decimal: 128514
// codepoint hexadecimal: 1f602
// UTF8 encoding: F0 9F 98 82
// Utf16 encoding: D8 3D DE 02
∑ JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

String

prototype