JavaScript (ES2026) reference · String Methods
JavaScript String charAt() Method
Return the character at a given index as a new string, or an empty string if the index is out of range.
JavaScript (ES2026) Since ES1
Syntax
string.charAt(index)
Parameters
| Parameter | Description |
|---|---|
index optional |
Position from 0. Default: 0 |
Return value
A one-character string, or "".
Examples
const name = "Ada";
console.log(name.charAt(0), name.charAt(2), JSON.stringify(name.charAt(9)));
Output
A a ""
const s = "hello";
console.log(s.charAt(1), s[1], s.at(1)); // three ways
Output
e e e
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
Related
string.at()· Return the character at an index, where negative indexes count from the end: str.at(-1) is the last character.string.charCodeAt()· Return the UTF-16 code unit (0 to 65535) at an index. For emoji and other astral characters use codePointAt().string.codePointAt()· Return the full Unicode code point at an index, correctly handling emoji and other characters outside the BMP.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial