Standard built-ins

String.prototype.padStart()

Try the free JavaScript compiler

Repeats and truncates filler at the start until the target length is reached; never truncates existing text.

Formal Syntax & Structure

javascript syntaxjavascript
text.padStart(targetLength, [padString])

Parameters & Attributes

NameTypeDescription
targetLengthNumberDesired code-unit length.
padStringStringFiller, default space.

Return Value

String

Padded text or original value.

Working Example

Example Snippetjavascript
console.log("1".padStart(3,"0"));
JavaScript Reference