String.prototype.charAt()

Returns the character (UTF-16 code unit) at the specified index.

Since ES1 Spec ↗

Syntax

str.charAt(index)

Parameters

NameTypeRequiredDescription
index number No Zero-based index of the character. Defaults to 0.

Returns

string — A single-character string, or an empty string if the index is out of range.

Examples

console.log('hello'.charAt(1));
Output
e
console.log('abc'.charAt(9));

Notes

Returns an empty string (not undefined) for out-of-range indices. Operates on UTF-16 code units, so it splits characters outside the BMP (use `at` or iteration for full code points).

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also