Javascript String endWith(str)

Description

Javascript String endWith(str)


String.prototype.endWith = function(str) {
  var reg = new RegExp(str + "$");
  return reg.test(this);
};

Javascript String endWith(str)

String.prototype.endWith = function(str){
  return this.lastIndexOf(str) == this.length - str.length;
};

Javascript String endWith(str)

String.prototype.endWith=function(str){
    if(str==null||str==""||this.length==0||str.length>this.length)
        return false;
    if(this.substring(this.length-str.length)==str)
        return true;
    else/*from  w w w .  ja  va 2 s.com*/
        return false;
    return true;
}

Javascript String endWith(str)

String.prototype.endWith = function (str) {
 var reg = new RegExp(str + "$");
 return reg.test(this);
}

Javascript String endWith(str)

String.prototype.endWith = function(str) {
 var result = true;
 if (typeof(str)=='string' && str.length <= this.length) {
  for (var i=0,len=str.length,thisLen=this.length;i<len;i++) {   
   if (str.charAt(len-1-i) == this.charAt(thisLen-1-i)) {
    continue;/*  w ww .  j  a v a2 s  . co m*/
   } else {
    result = false;
    break;
   }
  }
 } else {
  result = false;
 }
 return result;
}



PreviousNext

Related