You’ll have to store the number as a string, as JavaScript will strip the leading zeroes if its defined as a number.
You can use String.prototype.padStart() - JavaScript | MDN
let n = 1
let pad = String(n).padStart(4, '0');
console.log(pad); // '0001'