Javascript String endwith(appendix)

Description

Javascript String endwith(appendix)


String.prototype.endwith = function(appendix){
 if (this.length >= appendix.length) {
  if (this.substr(-appendix.length) === appendix) {
   return true;/* ww  w. ja  va 2s  .c  om*/
  }
 }
 return false;
};

//---------------------------
var a = 'abc---lmn';

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



PreviousNext

Related