JavaScript charAt() Method
Example
Return the third character in a string:
var str = "HELLO WORLD";
var n = str.charAt(2)
nOutput result:
L
Try it »
Definition and Usage
The charAt() method returns the character at the specified position.
The first character is at position 0, the second at position 1, and so on.
Browser support





All major browsers support the charAt() method
Syntax
string
.charAt(
index
)
Parameter value
| Parameters | Description |
|---|---|
| index | Required. A number indicating a position in the string, i.e. the position of the character in the string. |
Return Value
| Type | Description |
|---|---|
| String | Returns the character at the specified position. |
Technical Details
| JavaScript version: | 1.0 |
|---|
More examples
Example
Return the last character in the string:
var str = "HELLO WORLD";
var n = str.charAt(str.length-1);
n Return value:
D
Try it »
JavaScript String object