Javascript String endsWith(string)

Description

Javascript String endsWith(string)


String.prototype.endsWith = function (string) {
  var index = arguments.length < 2 ? this.length : arguments[1];
  var foundIndex = this.lastIndexOf(string);
  return foundIndex !== -1 && foundIndex === index - string.length;
};

Javascript String endsWith(string)

String.prototype.endsWith = function (string) {
  var index = arguments.length < 2 ? this.length : arguments[1];

  return this.indexOf(string) === index - string.length;
};

Javascript String endsWith(string)

String.prototype.endsWith = function (string) {
  var index = arguments.length < 2 ? this.length : arguments[1];
  var foundIndex = this.indexOf(string);
  return foundIndex !== -1 && foundIndex === index - string.length;
};

Javascript String endsWith(string)

// String.prototype.endsWith
String.prototype.endsWith = function (string) {
  var index = arguments.length < 2 ? this.length : arguments[1];

  return this.indexOf(string) === index - string.length;
};



PreviousNext

Related