Javascript String substring(start, end)

Description

Javascript String substring(start, end)


// alias for slice
String.prototype.substring = function(start, end) {
  if (start < 0) {
    start = start + this.length;/* www  . j a  va  2  s  .com*/
  }
  if (!end) {
    end = this.length;
  } else if (end < 0) {
    end = end + this.length;
  }
  
  var s = "";
  for (var i = start, len = this.length; i < end && i < len; i++) {
    s += this[i];
  }
  
  return s;
};



PreviousNext

Related