Thursday, July 31, 2014

javascript: my version of endswith

C# has EndsWith however javascript does not provide that. Here is my version of it:
function  endsWith( targetStr, str ) {
    return targetStr.substr( -1 * str.length, str.length ) === str;
  }

or
if ( typeof String.prototype.endsWith != 'function' ) {
  String.prototype.endsWith = function( str ) {
    return this.substr( -1 * str.length, str.length ) === str;

  }
};

No comments:

Post a Comment