

The string includes() method is introduced in ES6. This will produce the following result - Contains point 3. In the example program below, we use string indexOf() method to check whether the string “ Tutorialspoint: Free Video Tutorial” contains a substring “ point” or not. Start - the index to start from (default is 0). Syntax string.indexOf(searchvalue, start) Parameters The string indexOf() method is an ES1 feature. This method cannot search against a regular expression.

The string indexOf() method is case-sensitive. It returns the position of the first occurrence of a value (substring) in the string otherwise it returns -1 if the value is not found. The string indexOf() method can be used to check if a string contains a substring or not. This will produce the following result - Contains Point!" 2. Var str = "Tutorialspoint: Free Video Tutorials" ĭocument.write("Does not contain Point" ) You can try to run the following code to check whether the string “ Tutorialspoint: Free Video Tutorial” contains a substring “point” in or not. SearchValue is a regular expression or a string (will be converted to a regular expression). The string search() method is an ES1 feature. It matches the string against a regular expression and returns the index (position) of the first match. The string search method can be used to search a text (using regular expression) in a string. In this article, we use the following three methods for this purpose. JavaScript provides us with different methods to check whether a string contains a substring or not.
