There are a few ways you can accomplish this. If you are using a version of ES that's high enough, you can use
padStart[
^] (this is available from ES2017 onwards). If you don't have that available, you can write your own easily enough.
padStart(num:number, size:number): string {
let baseString = num+"";
while (baseString.length < size) baseString = "0" + baseString;
return baseString;
}
There are other versions of this code, but that's a simple way to accomplish this. Use
padStart
without adding this code and, if you're on ES2015 or so, then add this code.