In most languages like C# for example given a string you can test (boolean) if that string contains another string, basically a subset of that string.
string x = test2;
if(x.contains("test"))
// do something
How can I do this in a simple way with Javascript/Jquery?
This is done with indexOf, however it returns -1 instead of False if not found.
Syntax
string.indexOf(searchValue[, fromIndex])Parameters
searchValue–A string representing the value to search for.
fromIndex–The location within
stringto start the search from. It can be any integer between 0 and the length ofstring. The default value is 0.Return
The first index in
stringat which the start of the substring can be found, or -1 ifstringdoes not contain any instances of the substring.