charAt (JavaScript)
Gets the character at a specified index.
Defined in
String (Standard - JavaScript)Syntax
charAt(pos:int) : string
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 |
---|---|
string |
The character at the specified index, or an empty string if the index is out of range. |
Examples
This example returnsFirst
= P Last = o
.var cities = new String("Paris Moscow Tokyo");
"First = " + cities.charAt(0) +
"\nLast = " + cities.charAt(cities.length() - 1)