Last active
December 5, 2022 12:52
-
-
Save hamiltondanielb/a174bc415fdd71966de1 to your computer and use it in GitHub Desktop.
ES6 String contains, starts with, ends with to ES5
This file contains hidden or 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
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