Skip to content

Instantly share code, notes, and snippets.

@mikesprague
Created September 13, 2014 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesprague/7855784861d07cb0f3ae to your computer and use it in GitHub Desktop.
Save mikesprague/7855784861d07cb0f3ae to your computer and use it in GitHub Desktop.
Adds a String function named endWith() to check and return the last character (if the function hasn't already been overridden)
if ( typeof String.prototype.endsWith !== 'function' ) {
String.prototype.endsWith = function( str ) {
return this.indexOf( str.toString(), this.length - str.length ) !== -1;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment