Javascript String substr(start, length)

Description

Javascript String substr(start, length)


String.prototype.substr = function(start, length) {
  if (start < 0) {
    start = start + this.length;/*from ww  w  .j a v a 2s .c  o m*/
  }
  if (!length) {
    length = this.length - start;
  }
  
  var s = "";
  for (var i = start, len = this.length; i < start + length && i < len; i+) {
    s += this[i];
  }
  
  return s;
};



PreviousNext

Related