JavaScript 2025 · Strings
Pad a string
Pad on the left, for example to make 7 into 07.
const hour = String(7).padStart(2, "0");
Official JavaScript 2025 documentation
JavaScript 2025 · Strings
Pad on the left, for example to make 7 into 07.
const hour = String(7).padStart(2, "0");
Official JavaScript 2025 documentation
Was this page helpful?