Availability: |
| ||||||||
Property/method value type: | String primitive | ||||||||
JavaScript syntax: | - | myString.charAt(aPosition) | |||||||
Argument list: | aPosition | A valid character position within the string |
The character at the position in the string indicated by the argument value is returned by this method.
This may involve converting the receiving object to a string first. This means it can be used generically on many kinds of object.
If there is no character at that position, an empty string will be returned.
The result will be a string value and not a String object.
Note that there is no complementary setCharAt() method because strings are immutable and cannot be changed.
<HTML> <HEAD> </HEAD> <BODY> <TABLE BORDER=1> <TR> <TH>Index</TH> <TH>Char</TH> </TR> <SCRIPT> myString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for(myEnum=0; myEnum<myString.length; myEnum++) { document.write("<TR>"); document.write("<TD>"); document.write(myEnum); document.write("</TD>"); document.write("<TD>"); document.write(myString.charAt(myEnum)); document.write("</TD>"); document.write("</TR>"); } </SCRIPT> </TABLE> </BODY> </HTML>
Prev | Home | Next |
String.bold() | Up | String.charCodeAt() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |