| | 6.9.1.String.charAt() |
|
Syntax |
|
The charAt() method returns the character located at the indexed, num, position passed. |
This indexing is done from left to right starting with the 0 (zero) position. |
If the num passed is not a valid index in the string, -1 is returned. |
<html>
<head>
<title>Using the String.charAt() method</title>
</head>
<body>
<script language="JavaScript">
<!--
var myString = new String("This is a test, small test.");
var myIndex = prompt("Please enter a number", "");
var myChar = myString.charAt(myIndex);
document.write('<b>The string you searched through was: </b>' + myString);
document.write('<br>The ' + myIndex + ' character in this string is ');
if (myChar == " "){
document.write('<space>');
}else{
document.write(myChar);
}
document.close();
-->
</script>
</body>
</html>
|
|
|