I have a number in Javascript, that I know is less than 10000 and also non-negative. I want to display it as a four-digit number, with leading zeroes. Is there anything more e
Latest with ES6 repeat() method:
const length_required = 5; let num = 10; num = "0".repeat(length_required - String(num).length) + num; console.log(num) // output: 00010 let num = 1000; num = "0".repeat(length_required - String(num).length) + num; console.log(num) // output: 01000