Last active
December 13, 2015 18:29
-
-
Save pbojinov/4956018 to your computer and use it in GitHub Desktop.
String.prototype.contains
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
/** | |
* Wrapper for indexOf() to return true || false if string is contained within another string | |
* Will not not extend String if 'contains' already exists | |
* | |
* @param {String} | |
* @return {Boolean} | |
*/ | |
if (typeof String.prototype.contains === 'undefined') { | |
String.prototype.contains = function(it) { | |
return this.indexOf(it) !== -1; | |
}; | |
} | |
'pbojinov'.contains('p') === true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment