How to add N zeros to an empty string in TypeScript

1 Answer

0 votes
function padLeftZeros(str: string, length: number) {
    return "0".repeat(length);
}
  
const n: number = 4;
let emptyString: string = "";
  
emptyString = padLeftZeros(emptyString, n);
  
console.log(emptyString);
  
  
  
  
/*
run:
  
"0000" 
  
*/

 



answered May 28, 2024 by avibootz

Related questions

1 answer 128 views
2 answers 144 views
2 answers 133 views
1 answer 117 views
117 views asked May 26, 2024 by avibootz
1 answer 135 views
2 answers 124 views
124 views asked May 26, 2024 by avibootz
2 answers 153 views
...