string contains other or not  [ 678 views ]

in c# we can use to check a string

// This example demonstrates the String.Contains() method 
using System;

class Sample 
{
    public static void Main() 
    {
    string s1 = "The quick brown fox jumps over the lazy dog";
    string s2 = "fox";
    bool b;
    b = s1.Contains(s2);
    Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
    }
}
/*
This example produces the following results:

Is the string, s2, in the string, s1?: True
*/

So I need a similar function in javascript. Here is:

if (!String.prototype.Contains) {
  Object.defineProperty(String.prototype, 'Contains', {
    enumerable: false,
    configurable: false,
    writable: false,
    value: function (s) {
      return !!~this.indexOf(s);
    }
  });
};
#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }