Javascript String toPaddedString(length, padchar)

Description

Javascript String toPaddedString(length, padchar)


String.prototype.toPaddedString = function(length, padchar) {
  length = length || 2;// www.j  a v  a 2s. com
  padchar = padchar || '0';
  var str = this.toString();
  while (str.length < length) {
    str = padchar + str;
  }
  return str;
};



PreviousNext

Related