Home  /  Questions  /  Question



139   96.7
Oct 23, 2013


How to find a substring in another string in JavaScript?

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

Example: 

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

Thank you.
Chris



588   99.9
Sep 21, 2014
This should do it.

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

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

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

    </script>