Javascript String pad(n, char)

Description

Javascript String pad(n, char)


String.prototype.pad = Number.prototype.pad = function(n, char)
{
  char = (typeof char !== 'undefined') ? char : 0;
  for ( var i=0,nstr = ''; (n-(this.toString()).length) > i; ++i)
    nstr += char;//from   w ww .j a  v  a  2s .co m

  return nstr + this;
};



PreviousNext

Related