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

Total Post:12

Points:84
 1802  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. 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.

      Modified On Mar-29-2018 03:51:43 AM

Answer

NEWSLETTER

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