Javascript String trimFirst(/* String || Array */ str)

Description

Javascript String trimFirst(/* String || Array */ str)

String.prototype.trimFirst = function(/* String || Array */ str) {
  if (typeof str == 'string') {
    return this.replace(new RegExp("^" + RegExp.escape(str)), "").trim();
  } else {//ww  w. ja va2 s  . co m
    var result = this;
    for(var i=0; i < str.length; i++) {
      result = result.replace(new RegExp("^" + RegExp.escape(str[i])), "").trim();
    }
    return result;
  }
}



PreviousNext

Related