Last active
October 13, 2015 11:47
-
-
Save davidwaterston/4191094 to your computer and use it in GitHub Desktop.
Javascript: Case-sensitive 'starts with'
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.lastIndexOf(str, 0) === 0); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple Javascript function to tell if one string starts with another.
Usage:
if (myString.startsWith("anything") { do something… }
NOTE: As always, make sure this is defined before it is used!