how to pad string js

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

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