Function Updated 17 Oct 2026
String.padStart(targetLength, [padString])
Pads the start of the string with another string until it reaches the given length — typically for leading zeros. padEnd() pads at the end in the same way.
The older template helpers padLeft(text, fill, length) and padRight(text, fill, length) do the same, with the text as first argument.
Parameters
targetLengthnumberrequiredLength of the resulting string. If the string is already this long or longer, it is returned unchanged.
padStringstringoptionalText to pad with, repeated and cut to fit. Default is a space.
Returns
The padded string.
Example
Normal JavaScript, running in the browser or on the Docly™ server.
const day = 7;
write(String(day).padStart(2, "0")); // 07
write("\n");
write("5".padStart(4, "ab")); // aba5
write("\n");
write("Total".padEnd(10, ".") + "100"); // Total.....100The JavaScript above produces this output:
07
aba5
Total.....100