Nodejs String Ends With endWith(s)

Here you can find the source of endWith(s)

Method Source Code

String.prototype.endWith = function (s) {
    var d = this.length - s.length;
    return (d >= 0 && this.lastIndexOf(s) == d)
}

Related

  1. endswith(str)
    String.prototype.endswith = function(str)
      return this.slice(this.length - str.length) === str;
    };
    
  2. endswith(str)
    String.prototype.endswith = function(str) {
      return (this.indexOf(str, this.length - str.length) !== -1) ? true: false;
    
  3. endswith(suffix)
    String.prototype.endswith = function(suffix) {
        return this.indexOf(suffix, this.length - suffix.length) !== -1;
    };
    
  4. sl_endsWith(str)
    String.prototype.sl_endsWith = function(str) {
      if (typeof String.prototype.endsWith != 'function') {
        return this.indexOf(str, this.length - str.length - 1) !== -1;
      return this.endsWith(str);
    String.prototype.sl_startsWith = function(str) {
      if (typeof String.prototype.startsWith != 'function') {
        return this.slice(0, str.length) === str;
    ...
    
  5. endWith(char)
    String.prototype.endWith = function(char) {
      let string = String(this);
      return (new RegExp(".*" + char + "$").test(string));
    
  6. endWith(s)
    String.prototype.endWith = function(s) {
      if (s === null || s === "" || this.length === 0 || s.length > this.length)
        return false;
      if (this.substring(this.length - s.length) == s)
        return true;
      else
        return false;
      return true;
    
  7. endWith(str)
    String.prototype.endWith = function(str){
      return this.lastIndexOf(str) == this.length - str.length;
    };
    
  8. endWith(str)
    String.prototype.endWith = function(str) {
      var reg = new RegExp(str + "$");
      return reg.test(this);
    };
    
  9. 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;