★ wanayoo — archive 1999 http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAtNouvelle recherche | Portail wanayoo

Mozilla.com

charCodeAt

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

Syntax

var codepoint = string.charCodeAt(index);

Parameters

index 
An integer greater than 0 and less than the length of the string; if unspecified, defaults to 0.

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 greater then 0 and less than the length of the string.

Backward Compatibility

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.

Examples

Example: Using charCodeAt

The following example returns 65, the Unicode value for A.

"ABC".charCodeAt(0) // returns 65

See Also

fromCharCode, charAt


Page last modified 16:41, 6 Aug 2008 by Sheppy

Tags:

Files (0)