Javascript String leftPad(len, char)

Description

Javascript String leftPad(len, char)




// left pad string to length of LEN with CHAR or " "
String.prototype.leftPad = Date.prototype.leftPad || function (len, char) {

  char = char || " ";
  var str = this;

  while (str.length < len) {
    str = char + str;/*from w  w w .  j a v a  2 s. c  o m*/
  }

  return str.toString();
}



PreviousNext

Related