Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ES6 String contains, starts with, ends with to ES5
String.prototype.contains = String.prototype.contains || function(str) {
return this.indexOf(str) >= 0;
};
String.prototype.startsWith = String.prototype.startsWith || function(prefix) {
return this.indexOf(prefix) === 0;
};
String.prototype.endsWith = String.prototype.endsWith || function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) >= 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.