String objects don't have a test
method, but Regex
objects do. To create a Regex object, you use the RegExp
constructor:
var quote = new RegExp("jazz Dance");
Or, you can use the Regex literal, like so:
var quote = /jazz Dance/;
Note: don't use quotes around it since that will just create a normal string wrapped in slashes.
To learn about the differences between the two, check this article on MDN.
After you've created a Regex object, you can call its test
method and pass in the string you want to search in, like this:
quote.test(sup_spec)
This will return True/False
representing whether your needle (the regex) matched the haystack (the string) or not.
As mentioned in other responses, if you don't need the power of Regex, you can just use the indexOf
method of String objects, which takes the needle (string you're searching for) and returns the first position where it matches, or -1 if it can't find it.