Core JavaScript 1.5 Reference:Global Objects:String:charCodeAt
From MDC
Contents |
[edit] Summary
Returns a number indicating the Unicode value of the character at the given index.
| Method of String | |
| Implemented in: | JavaScript 1.2, NES3.0
JavaScript 1.3: returns a Unicode value rather than an ISO-Latin-1 value. |
| ECMA Version: | ECMA-262 |
[edit] Syntax
var codepoint = string.charCodeAt(index);
[edit] Parameters
-
index - An integer between 0 and 1 less than the length of the string; if unspecified, defaults to 0.
[edit] Description
Unicode code points range from 0 to 1,114,111. The first 128 Unicode code points are a direct match of the ASCII character encoding. For information on Unicode, see the Core JavaScript 1.5 Guide. Note that charCodeAt will always return a value that is less than 65,536.
charCodeAt returns NaN if the given index is not between 0 and 1 less than the length of the string.
[edit] Backward Compatibility
[edit] JavaScript 1.2
The charCodeAt method returns a number indicating the ISO-Latin-1 codeset value of the character at the given index. The ISO-Latin-1 codeset ranges from 0 to 255. The first 0 to 127 are a direct match of the ASCII character set.
[edit] Examples
[edit] Example: Using charCodeAt
The following example returns 65, the Unicode value for A.
"ABC".charCodeAt(0) // returns 65