Case-sensitive 'contains'


/ Published in: JavaScript
Save to your folder(s)

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

Usage:

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


Copy this code and paste it in your HTML
  1. if (typeof String.prototype.contains != 'function') {
  2. String.prototype.contains = function(str) {
  3. return this.indexOf(str) >= 0;
  4. };
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.