I want to convert 1,2,3,..9,10,11,12...24 to 01,02,03,...09,10,11,12,...24. I tried these solutions. None of these solved my purpose:
- How to format numbers by prepending 0 to single-digit numbers?
- How to output numbers with leading zeros in JavaScript [duplicate]
- How can I pad a value with leading zeros?
I'm working on an Angular project and I'm doing this in Typescript. Here is my code:
monthpikcer.component.ts
monthSlice() {
    let monthStartingIndex = 0;
    monthStartingIndex = ("0" + monthStartingIndex).slice(-2); //error
    let monthEndingIndex = 24;
    for(monthStartingIndex =0; monthStartingIndex < monthEndingIndex; monthStartingIndex++) {
    ...
    } 
}
But for line monthStartingIndex = ("0" + monthStartingIndex).slice(-2), I'm getting an error:
Type 'string' is not assignable to type 'number'.
I want it to be 01, 02, 03...10,11,12,13...24. Please tell me how to do it without changing the data type of my variables because later I've to do some arithematics with them.
 
     
     
    