Nodejs String Ends With endwith(appendix)

Here you can find the source of endwith(appendix)

Method Source Code

String.prototype.endwith = function(appendix){
   if (this.length >= appendix.length) {
      if (this.substr(-appendix.length) === appendix) {
         return true;
      }//from   w  w  w.  ja v a2  s.  c o m
   }
   return false;
};

var a = 'abc---lmn';

console.log(a.endwith('mn')); //should be true
console.log(a.endwith('asdfasdfasdfasdfabc---lmn')); //should be false

Related

  1. endWith(str)
    String.prototype.endWith = function(str){
      return this.lastIndexOf(str) == this.length - str.length;
    };
    
  2. endWith(str)
    String.prototype.endWith = function(str) {
      var reg = new RegExp(str + "$");
      return reg.test(this);
    };
    
  3. 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
        return false;
      return true;
    
  4. 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;
          } else {
            result = false;
            break;
    ...
    
  5. endWith(subStr)
    String.prototype.endWith = function (subStr) {
      if (subStr.length > this.length) {
        return false;
      else {
        return (this.lastIndexOf(subStr) == (this.length - subStr.length));
    };