Adding contains(t) function to JavaScript String.prototype
November 25th, 2006 by Ivan Uzunov
The contains(t) function returns true if the string contains the value of the parameter "t" and false if it doesn’t. To extend the String.prototype with the contains(t) function I use this line of code:
String.prototype.contains = function(t) { return this.indexOf(t) >= 0 ? true : false }
This is sample code how to use the contains(t) function:
contains, JavaScript, String.prototypevar sMyVar = new String (" testing text ");
alert(sMyVar.contains(’testing’));
//use it with the value of a text box
document.getElementById("txtMyTextBox").value.contains(’some text’);



