Return the first character of a string:
The result of res will be:
More "Try it Yourself" examples below.
The charAt() method returns the character at the specified index in a string.
The index of the first character is 0, the second character is 1, and so on.
Tip: The index of the last character in a string is string.length-1, the second last character is string.length-2, and so on (See "More Examples").
Method | |||||
---|---|---|---|---|---|
charAt() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
index | Required. An integer representing the index of the character you want to return |
Return Value: | A String, representing the character at the specified index, or an empty string if the index number is not found |
---|---|
JavaScript Version: | 1.0 |
Return the last character of a string:
The result of res will be: