The example in this article describes the way JavaScript checks whether a substring is in a string. Share to everyone for your reference, specific as follows:
var strnew=" Hello Raghu How are U "//checking existence in entire string if (strnew.indexof ("Raghu")!=-1) {alert ("Exists");}/* Checking existence at the ' end of ' of string for example, variable result1 in the F ollowing example is assigned the value of true because the word "Ishmael" appears at the end of the string.
Variable RESULT2 is assigned a value of false because "Raghu" doesn ' t appear at the end of the string.
* * RESULT1 =/raghu$/.test ("Call Me Raghu"); RESULT2 =/raghu$/.test ("Call Me Raghu".
Some years ago "); /* Checking existence in the begining of a string in the following example, variable RESULT1 is assigned the value of True Because the word "birds" appears at the beginning of the string.
Variable RESULT2 is assigned the value of false because "birds" doesn ' t appear at the beginning of the string.
* * RESULT1 =/^birds/.test ("Birds Fly");
RESULT2 =/^birds/.test ("Big Birds Fly");
More readers interested in JavaScript-related content can view the site topics: "JavaScript Search Algorithm Skills Summary" and "JavaScript data structure and algorithm skills summary"
I hope this article will help you with JavaScript programming.