By 05/02/2014 13 Comments

How to check if a string contains a substring in Javascript

Check substring

  • each single character in an string is called a substring


  • This function is used for check the presence of a substring
  • This is a simple method for testing the string

For check if a string contains a substring in Javascript use the following code snippet.


if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
return -1;

if (!String.prototype.contains) {
String.prototype.contains = function (arg) {
return !!~this.indexOf(arg);


Posted in: JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .