Last active
January 4, 2016 07:19
-
-
Save designbyadrian/8588162 to your computer and use it in GitHub Desktop.
Easy startsWith/endsWith proto functions for the String object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://stackoverflow.com/questions/646628/javascript-startswith