Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Last active December 13, 2015 18:29
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 pbojinov/4956018 to your computer and use it in GitHub Desktop.
Save pbojinov/4956018 to your computer and use it in GitHub Desktop.
String.prototype.contains
/**
* 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