View difference between Paste ID: 0g4g1uAU and NgZW66cr
SHOW: | | - or go back to the newest paste.
1
function padLeft(width, char) {
2
 var pad = '';
3
 for (var i = 0; i < width; i++) {
4
 pad += char;
5
 }
6
 return pad;
7
}
8
var str = '1100';
9
var pad = padLeft(8, '0');
10-
console.log(pad.substring(0, pad.length - str.length) + str); //This will print on the console -> '00001100'
10+
var paddedString = pad.substring(0, pad.length - str.length) + str;
11
console.log(paddedString); //This will print on the console -> '00001100'