To determine whether a string is a substring of another, you can use the indexOf()
method. For example, the following code writes the string to the console only if it contains the word think
:
var myStr = "I think, therefore I am.";
if (myStr.indexOf("think") != -1){
console.log (myStr);
}