Applies to: String Object
The charCodeAt method returns the Unicode encoding of the specified character.
Syntax
stringObj.charCodeAt(index)
The charCodeAt method syntax has these parts:
Part |
Description |
stringObj |
Required. A String object or literal. |
index |
Required. The zero-based index of the specified character. |
Return value
The charCodeAt method returns the Unicode encoding of the specified character.
Example
If there is no character at the specified index, NaN is returned.
The following example illustrates the use of the charCodeAt method:
function getCharCode(str,pos) { var s; s = str.charCodeAt(pos - 1); // Return Unicode character code. return(s); } document.write(getCharCode("ABCDEFGHIJKLMNOPQRSTUVWXYZ","10"));
|
To run the code, paste it into JavaScript Editor, and click the Execute button.
See also: fromCharCode Method, String Object Methods |