JavaScript String.prototype.charAt() Method
The charAt() method returns the character at a given index of a string, or an empty string if there is none.
Description
The charAt() method returns a new string containing the single UTF-16 code unit at the given index. It doesn't accept negative indexes; use at() for that. Square-bracket access, str[i], does the same thing but returns undefined for missing indexes.
Like at(), it works with UTF-16 code units, so it returns only half of a character for emoji and other characters outside the Basic Multilingual Plane. Use codePointAt() or spread the string into an array when you need whole characters.
Because it returns an empty string rather than undefined for out-of-range indexes, you can safely chain other string methods onto its result, as in the classic capitalize pattern s.charAt(0).toUpperCase() + s.slice(1), which works even when s is empty.
Syntax
string.charAt(index)Parameters
- indexThe position of the character, from 0. Defaults to 0.
Return Value
The character at that position, or an empty string if the index is out of range.
Example
Browser Support
The following information will show you the current browser support for the String.prototype.charAt() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





