Javascript String contains()

Description

Javascript String contains()


////from  w ww .ja  v a  2  s .c  o  m
// Check if string contains any of the supplied words.
//
// Usage:
// "".contains(a, b, ...);
//
// Returns [true|false]
//
String.prototype.contains = function() {
 var args = arguments;
 for (var i in args) {
  var str = args[i];
  if (typeof str === "string" && this.indexOf(str) > -1) {
   return true;
  }
 }
 return false;
}

Javascript String contains()

String.prototype.contains = function() {
    return String.prototype.indexOf.apply( this, arguments ) !== -1;
};



PreviousNext

Related