Page 232 - Web_Application_v2.0_C12_Fb
P. 232
10. The charAt() Method: The charAt() method returns the character at a specified index in a string.
Example 40: To demonstrate the use of chatAt method
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>charAt() Method</TITLE>
</HEAD>
<BODY>
<H2>The charAt() Method</H2>
<P>The charAt() method returns a character from a string.</P>
<P id="demo1"></P>
<SCRIPT>
var text = "JavaScript";
document.getElementById("demo1").innerHTML = text.charAt(4);
</SCRIPT>
</BODY>
</HTML>
Output:
11. The search() Method: The search() method searches a string for a specified value (using a regular expression)
and returns the position of the first match. If no match is found, it returns -1.
Example 41: To demonstrate the use of search method
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>search() Method</TITLE>
</HEAD>
<BODY>
<H2>The search() Method</H2>
<P>The search() method finds the position of a match.</P>
<P id="demo1"></P>
<SCRIPT>
var text = "The quick brown fox jumps over the lazy dog";
230 Touchpad Web Applications (Ver. 2.0)-XII

