Skip to content

Instantly share code, notes, and snippets.

@antoine-pous
Created December 20, 2016 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoine-pous/cad6cc97a500666fbffe43359abb7454 to your computer and use it in GitHub Desktop.
Save antoine-pous/cad6cc97a500666fbffe43359abb7454 to your computer and use it in GitHub Desktop.
Detect if string start with needle
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