Strings
How to check whether a string contains a substring in Javascript
In order to check whether a substring is included in a string in Javascript you can use the following two ways:
indexOf()
The most traditional way is to use the indexOf() method against a string. This method returns the index (number) of the found substring or -1 if the substring is not part of the given string. For example the returned value of “st” in “tester” is 2.
includes()
Since ECMAScript 6 the includes() method is available which returns either true or false, if the substring will be found inside the given string.
Use the equal sign to assign a string to a variable. You can either use single or double quotes.