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 string to start the search from. It can be any integer between 0 and the length of string. The default value is 0.
Return 
 The first index in string at which the start of the substring can be found, or -1 if string does not contain any instances of the substring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With