Javascript String pad(l)

Description

Javascript String pad(l)


String.prototype.pad = function(l) {
 if (this.length >= Math.abs(l)) {
  return this + '';
 } else if (l > 0) {
  return this + Array(l - this.length).join(' ');
 } else if (l < 0) {
  return Array(-l - this.length).join(' ') + this;
 } else {// w  ww.j a  v  a2s.  c  o m
  return '';
 }
};



PreviousNext

Related