There is the newer
includes function which was introduced in ES2015 which allows you to tell if a string contains a substring. This function returns a boolean value of
Alternatively, if you need to either:
- Need to not only know if a string contains a substring, but also it’s position within the string..
indexOf is a better match for you.
It works as follows:
The second argument,
position, is not mandatory as shown in the below examples: