Javascript String pad(side, ch, maxLength)

Description

Javascript String pad(side, ch, maxLength)


String.prototype.pad = function(side, ch, maxLength) {
  var padding = "";
  
  for(var i = this.length; i < maxLength; i++) {
    padding += ch;//www .j a v  a2  s . co m
  }
  
  return (side === "left") ? (padding + this) : (this + padding);
};



PreviousNext

Related