/ Published in: JavaScript
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!
Usage:
if (myString.startsWith("anything") {
do something…
}
NOTE: As always, make sure this is defined before it is used!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function(str) { return (this.lastIndexOf(str, 0) === 0); }; }