how to pad string js

Solutions on MaxInterview for how to pad string js by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to pad string js"
Phillipa
22 Jul 2016
1const str1 = '5';
2
3console.log(str1.padStart(2, '0'));
4// expected output: "05"
5
6const fullNumber = '2034399002125581';
7const last4Digits = fullNumber.slice(-4);
8const maskedNumber = last4Digits.padStart(fullNumber.length, '*');
9
10console.log(maskedNumber);
11// expected output: "************5581"
12