String.charCodeAt() (Method)

The Unicode code point value of a character within the string.

Availability:

ECMAScript edition - 2
JavaScript - 1.2
JScript - 5.5
Internet Explorer - 5.5
Netscape - 4.0
Netscape Enterprise server - 3.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-myString.charCodeAt(aPosition)
Argument list:aPositionA valid character position within the string.

This method returns the Unicode code point of the character at the indicated position.

Note that the string index positions start at 0 and not 1.

If there is no character at the indicated position the NaN value will be returned.

This method may involve the receiver being converted to a string and so it can be applied generically to many kinds of objects.

Warnings:

Example code:

   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <TABLE BORDER=1>
   <TR>
   <TH>Index</TH>
   <TH>Char</TH>
   <TH>Code</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("<TD>");
   document.write(myString.charCodeAt(myEnum));
   document.write("</TD>");
   document.write("</TR>");
   }
   </SCRIPT>
   </TABLE>
   </BODY>
   </HTML>

See also:Arithmetic type, Cast operator, Character handling, Character testing, Character-case mapping, File.stringToByte(), Integer constant, JavaScript to Java values, String.fromCharCode(), String.prototype, Window.atob()

insert figure 0026

Cross-references:

ECMA 262 edition 2 - section - 15.5.4.5

ECMA 262 edition 3 - section - 15.5.4.5