Nodejs String Ends With endsWith(value)

Here you can find the source of endsWith(value)

Method Source Code

String.prototype.endsWith = function(value) {
   if (!value)//from w  ww.j ava2s.  c o m
      return false;
   if (value.length > this.length)
      return false;

   var end = this.substring(this.length - value.length);
   return end === value;
};

Related

  1. endsWith(suffix)
    String.prototype.endsWith = function (suffix) {
      return this.substring(this.length - suffix.length) == suffix;
    };
    
  2. endsWith(t, i)
    String.prototype.endsWith = function(t, i) {
      if (i == false) {
        return (t == this.substring(this.length - t.length));
      } else {
        return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase());
    };
    
  3. endsWith(test)
    String.prototype.endsWith = function(test) {
      return this.length >= test.length && this.substr(this.length - test.length) == test;
    
  4. endsWith(text)
    String.prototype.endsWith = function (text) {
      return this.substring(this.length - text.length) === text;
    };
    
  5. endsWith(text)
    String.prototype.endsWith = function(text) {
        return text != null && this.lastIndexOf(text) == this.length - text.length;
    };
    
  6. endsWith(value)
    String.prototype.endsWith = function (value) {
      if (value == undefined || typeof (value) != "string" || value.length > this.length)
        return false;
      if (value.length == 0)
        return true;
      return this.substr(this.length - value.length) == value;
    };
    
  7. endsWith(value)
    String.prototype.endsWith = function(value) {
      if (this.length < value.length) {
        return false;
      } else {
        return Boolean(this.substr((this.length - value.length), (value.length + 1)) === value);
    
  8. endsWith(value)
    String.prototype.endsWith = function(value) {
      var substringLength = value.length;
      var thisLength = this.length;
      if (substringLength > thisLength) {
        return false;
      };
      var howMuchLettersNeedToBeRemooved = thisLength - substringLength;
      var endsString = this.substring(howMuchLettersNeedToBeRemooved);
      if (endsString === value) {
    ...
    
  9. endsWithAny(endings)
    String.prototype.endsWithAny = function (endings) {
      var string = this;
      return endings.some(function (ending) {
        return string.endsWith(ending);
      });
    };