Return to Kroll Design home page

JavaScript Tutorials

 
« Return

charAt method for strings

The charAt method returns the character at the specified location within a string.

Code:

<script type="text/javascript">
//<![CDATA[
my_string = "abcde";

char_position = 0;
document.write("The character at position ", char_position, " of \"", my_string, "\" is : ", my_string.charAt(char_position));
document.write("<br>");

char_position = 1;
document.write("The character at position ", char_position, " of \"", my_string, "\" is : ", my_string.charAt(char_position));
document.write("<br>");

char_position = 4;
document.write("The character at position ", char_position, " of \"", my_string, "\" is : ", my_string.charAt(char_position));
document.write("<br>");

char_position = 5;
document.write("The character at position ", char_position, " of \"", my_string, "\" is : ", my_string.charAt(char_position));
//]]>
</script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM