Skip to content

Instantly share code, notes, and snippets.

@davidwaterston
Created December 2, 2012 21:05
Show Gist options
  • Select an option

  • Save davidwaterston/4191070 to your computer and use it in GitHub Desktop.

Select an option

Save davidwaterston/4191070 to your computer and use it in GitHub Desktop.
Javascript: Case-sensitive 'contains'
if (typeof String.prototype.contains != 'function') {
String.prototype.contains = function(str) {
return this.indexOf(str) >= 0;
};
}
@davidwaterston
Copy link
Author

A simple Javascript function to determine if one string contains another.

Usage:

if (myString.contains("anything") { do something… }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment