/ Published in: JavaScript
                    
                                        
pads a string "2".pad(2, "0"); //02
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
String.prototype.pad = function(l, s){
return (l -= this.length) > 0
? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length)
: this;
};
Comments
 Subscribe to comments
                    Subscribe to comments
                
                