Home > DeveloperSection > Forums > How to search for a substring in a string in Javascript?
Anoop Singh
Anoop Singh

Total Post:12

Posted on    February-28-2011 2:18 AM

 JavaScript JavaScript 

 1 Reply(s)
 1299  View(s)
Rate this:

I'm new to Javascript and have requirement where I have to check whether particular sub string exist in a string or not.

Thanks in advance.

Alex R
Alex R

Total Post:40

Posted on    February-28-2011 2:26 AM

Hi Anoop,

You can search sub string in a string using search() method of Javascript

Here is the example,

var mainString = 'Hello world';

if (mainString.search('world') >= 0)


Hop this will solve your problem.

Don't want to miss updates? Please click the below button!

Follow MindStick