Posted By

davidwaterston on 03/16/12


Tagged

String


Versions (?)

Case-sensitive 'contains'


 / Published in: JavaScript
 

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

Usage:

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

  1. if (typeof String.prototype.contains != 'function') {
  2. String.prototype.contains = function(str) {
  3. return this.indexOf(str) >= 0;
  4. };
  5. }

Report this snippet  

You need to login to post a comment.