Docly Developers
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

targetLengthnumberrequired

Length of the resulting string. If the string is already this long or longer, it is returned unchanged.

padStringstringoptional

Text 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.....100