Check if string contains any of the supplied words. - Node.js String

Node.js examples for String:String Value

Description

Check if string contains any of the supplied words.

Demo Code

////from   ww  w.j av a2  s . c om
// 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;
}

Related Tutorials