I'm extracting number from a string and passing it to a function. I want to add 1 to it and then return the string while retaining the leading zeros. I was able to do it using a while loop but not a for loop. The for loop simply skips the zeros.
var addMoreZeros = (numStr)=> {
let newNumStr = (parseInt(numStr)+1).toString();
let zerosToAdd = numStr.length - newNumStr.length;
let zeroPadStr = "";
let i = 0;
while (i < zerosToAdd) {
zeroPadStr += "0";
i++;
}
//This doesn't work
//for(let i = 0; i++; i < zerosToAdd) {
// zeroPadStr+="0";
//}
return zeroPadStr + newNumStr;
}