![]() Finally, call this method with two different words as sub-string to the above main string.In this example, our main string is âHello Worldâ.Print out the message to the user accordingly. If it is greater than or equal to 0, means that the substring exists inside the given string. Inside the function, check the value of indexOf method.It prints out the result based on subString exists in mainString or not. subString is the sub-string and mainString is the main string. doesExist method takes two parameters. ![]() Also, the case-sensitive method searches the entire. ![]() The commented numbers in the above program denote the step number below : The includes () method checks whether a JavaScript string contains a substring and returns a boolean. 1 function doesExist ( subString, mainString ) //3 var mainString = "Hello World" //4 doesExist ( "Hello", mainString ) doesExist ( "Universe", mainString ) Explanation :
0 Comments
Leave a Reply. |