Javascript String contains(substring, ignoreCase)

Description

Javascript String contains(substring, ignoreCase)


// String Additions
////////////////////
String.prototype.contains = function(substring, ignoreCase) {
  var lowerSubString = substring.toLowerCase(),
  lowerThis = this.toLowerCase();/*  w w  w . j  a  v  a  2s .  com*/
  if (ignoreCase) {
    return lowerThis.indexOf(lowerSubString) > -1;
  } else {
    return this.indexOf(substring) > -1;
  }
}



PreviousNext

Related