JS: String.prototype.padEnd

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2017)

str.padEnd(n)

Return a new string, by adding space to the end of string so the length is n.

console.assert(
 "x".padEnd(3) === "x  ",
);
str.padEnd(n, padstr)

Use padStr to pad.

console.assert(
 "x".padEnd(3, "0") === "x00",
);
console.assert(
 "x".padEnd(4, "ab") === "xaba",
);

🛑 warning: if string contains a character outside of Basic Multilingual Plane (such as most emoji 🦋 or rarely used Chinese character), result of string methods may be unexpected. See JS: String Index and Code Unit.