Created
December 20, 2016 12:09
-
-
Save antoine-pous/cad6cc97a500666fbffe43359abb7454 to your computer and use it in GitHub Desktop.
Detect if string start with needle
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(!String.prototype.startWith) { | |
String.prototype.startWith = function(needle) { | |
return this.substr(0, needle.length) === needle; | |
} | |
} | |
// Usage | |
'Hello world!'.startWith('hello'); // false | |
'Hello world!'.startWith('Hello'); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment