Back to list
Views:   5.7K
Replies:  1

How to find a substring in another string in JavaScript?

Can anyone tell me how to find a substring within another string in JavaScript? 


My string is: "The language we use today is JavaScript".  
How do I determine whether this string contains "today"?

Thank you.
Christopher Ronny, Oct 23, 2013
Reply 1
This should do it.

        var testString = "The language we use today is JavaScript";

        function doesStringExist(input, token) {
            return input.indexOf(token) > 0;

        alert(doesStringExist(testString, "today"));


King Wilder, Sep 21, 2014
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.