Javascript String endsWith(suffix)

Description

Javascript String endsWith(suffix)


String.prototype.endsWith = function(suffix) {
  return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

Javascript String endsWith(suffix)

String.prototype.endsWith = function (suffix) {
  if (this.length < suffix.length)
    return false;
  return this.lastIndexOf(suffix) === this.length - suffix.length;
};

Javascript String endsWith(suffix)

String.prototype.endsWith = function(suffix) {
  return this.indexOf(suffix, this.length - suffix.length) !== -1;
}

Javascript String endsWith(suffix)

String.prototype.endsWith = function(suffix) {
    return this.match(suffix+"$") == suffix;
};

Javascript String endswith(suffix)

String.prototype.endswith = function(suffix) {
 if (this.length < suffix.length)
  return false;//from  w  ww .  j  a  v a2  s  .  c  om
 return this.lastIndexOf(suffix) === this.length - suffix.length;
}

Javascript String endsWith(suffix)

String.prototype.endsWith = function(suffix)
{
    return (this.substr(this.length - suffix.length) === suffix);
}

Javascript String endsWith(suffix)

var findLastMatch = function(regex, text) {
 var lastMatch = null;
 while ((m = regex.exec(text)) != null) {
  lastMatch = m;//  ww  w. j a  v a 2 s  .c  om
 }
 
 return lastMatch;
}

String.prototype.endsWith = function(suffix) {
 return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

String.prototype.startsWith = function(prefix) {
 return this.indexOf(prefix) == 0;
};

module.exports.findLastMatch = findLastMatch;

Javascript String endsWith(suffix)

String.prototype.endsWith = function (suffix) {
 "use strict";//from www  . j a v  a 2 s  .  c  o  m

 if (!suffix && typeof suffix !== 'string') {
  return false;
 }

 var stringPosition = this.length - suffix.length;
 var suffixIndex = this.indexOf(suffix, stringPosition);

 return suffixIndex === stringPosition;
};

Javascript String endsWith(suffix)

/**/*from w  ww  .jav  a  2  s.  c o  m*/
 * see if a string ends with a given string
 * 
 * Once ecmascript adds this natively, you should build core.js without this method:
 * @link http://wiki.ecmascript.org/doku.php?id=harmony%3astring_extras
 * @link http://jsperf.com/string-prototype-endswith/3
 * @function external:String.prototype.endsWith
 * @param {string} A substring expected to be in the beginning of this string
 * @return {boolean}
  * @example
  *  'some string'.endsWith('g') === true;
  *  'some string'.endsWith('string') === true;
  *  'some string'.endsWith('!') === false;
 */
String.prototype.endsWith = function (suffix){ 
    return this.indexOf(suffix, this.length - suffix.length) !== -1;
};



PreviousNext

Related