Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save designbyadrian/8588162 to your computer and use it in GitHub Desktop.
Save designbyadrian/8588162 to your computer and use it in GitHub Desktop.
Easy startsWith/endsWith proto functions for the String object
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function (str){
return this.slice(-str.length) == str;
};
}
@designbyadrian
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment