Skip to content

Instantly share code, notes, and snippets.

@antoine-pous
Created December 20, 2016 12:09
Show Gist options
  • 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