padStart < String < JavaScript
The padStart() of a String pads the string with another string (repeated, if needed) until the resulting string reaches the given length. The padding is applied from the start of the string.
const amount = '5';
const amountPadStart = amount.padStart(2, '0');
console.log(amountPadStart);
// "05"
// advanced example
const fullNumber = '2034399002125581';
const last4Digits = fullNumber.slice(-4);
const maskedNumber = last4Digits.padStart(fullNumber.length, '*');
console.log(maskedNumber);
// "************5581"