Sometimes, we want to add left padding to a string with zeros with TypeScript.
In this article, we’ll look at how to add left padding to a string with zeros with TypeScript.
How to add left padding to a string with zeros with TypeScript?
To add left padding to a string with zeros with TypeScript, we can use the string padStart
method.
For instance, we write
const s: string = str.padStart(9, "0");
to prepend the str
string with 0’s until the length of it is 9.
Conclusion
To add left padding to a string with zeros with TypeScript, we can use the string padStart
method.