JavaScript (ES2026) reference · String Methods
JavaScript String padStart() Method
Pad the start of a string until it reaches a target length, for example zero-padding numbers like 007.
JavaScript (ES2026) Since ES2017
Syntax
string.padStart(targetLength, padString)
Parameters
| Parameter | Description |
|---|---|
targetLength |
The length of the result. |
padString optional |
Text to pad with. Default: " " |
Return value
A new string.
Examples
console.log(String(7).padStart(3, "0"), String(42).padStart(5));
Output
007 42
const card = "4242424242424242";
console.log(card.slice(-4).padStart(card.length, "*"));
Output
************4242
Version history
| Version | Change |
|---|---|
| JavaScript ES2017 | Added |
In other languages
str.zfill()· Pythonstr_pad()· PHP
Related
string.padEnd()· Pad the end of a string with another string until it reaches a target length. Useful for aligned text columns.string.slice()· Extract part of a string between two indexes; negative indexes count from the end.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial