therapycas.blogg.se

String contains js
String contains js











string contains js string contains js

Becuase this method will return a boolean value indicating whether a string contains a substring. Using the includes() method, you can also check whether a string contains a substring in JavaScript. If the substring is found, you print ‘Substring found!’ to the console otherwise, you print ‘Substring not found!’. In the above given example, you check whether the string ‘Hello, World!’ contains the substring ‘World’ using the indexOf() method. If the substring is not found, it returns -1.įor example using this method to check whether a string contains a substring in the following way: let str = 'Hello, World!' Using the indexOf() method, you check the string containing the substring and this method will return the index of the first occurrence of a substring in a string. Method 3: Using Regular Expressions Method 1: Using the indexOf() Method.How to check whether a string contains a substring in JavaScript?īy using the following methods, you can easily check whether a string contains a substring in JavaScript: Through this tutorial, you will learn how to check whether a string contains a character or substrings in javascript using the javaScript include(), indexOf() method. By using this you can check whether a string contains a substring in JavaScript. There are many methods in JavaScript for this. For example, Find the string like substring, get the length of the string, etc. When you are doing work with strings in javascript.













String contains js