JS: String.prototype.padEnd
(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.log("x".padEnd(3) === "x "); str.padEnd(n, padstr)-
Use padStr to pad.
console.log("x".padEnd(3, "0") === "x00"); console.log("x".padEnd(4, "ab") === "xaba"); // true
🛑 WARNING: string methods do not work the way you think if it contains characters outside of Unicode Basic Multilingual Plane (e.g. emoji 🦋.). See JS: String Index Code Unit