js pad code example
Example 1: javascript print int with leading zeros
function padLeadingZeros(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
padLeadingZeros(57, 3);
padLeadingZeros(57, 4);
Example 2: lpad javascript
str.padStart(targetLength [, padString])
Example 3: string padStart padEnd
let string = ‘Alice’;
string.padStart(10, ‘o’);
string.padEnd(10, ‘o’);
Example 4: js number padding to number of characters
var n = 123
String("00000" + n).slice(-5);
("00000" + n).slice(-5);
(" " + n).slice(-5);