HOW TO SEARCH FOR A SUBSTRING IN A STRING IN JAVASCRIPT?

Anoop Singh

Total Post:12

Points:84
Posted by  Anoop Singh
 1552  View(s)
Ratings:
Rate this:
Hi,

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.
  1. Alex R

    Post:40

    Points:280
    Re: How to search for a substring in a string in Javascript?

    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)

           alert('Exist');

    Hop this will solve your problem.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!