charCodeAt (JavaScript)

Gets the character at a specified index as an integer code.

Defined in

String (Standard - JavaScript)

Syntax

charCodeAt(pos:int) : int
Parameters Description
pos The index (position) of the character, where 0 is the index of the first character. The last index is the length of the string minus 1.
Returns Description
int The Unicode value of the character at the specified index, or an empty string if the index is out of range.

Usage

The return value is the standard Unicode code for the character, in the range 0 through 65535.

Examples

This example displays First = 80 Last = 111.
var cities = new String("Paris Moscow Tokyo");
"First = " + cities.charCodeAt(0) +
 "\nLast = " + cities.charCodeAt(cities.length() - 1)