String.prototype.at()

Returns the character at a given index, supporting negative indices.

Since ES2022 Spec ↗

Syntax

str.at(index)

Parameters

NameTypeRequiredDescription
index number Yes Index of the character. Negative values count back from the end.

Returns

string — A single-character string, or undefined if out of range.

Examples

console.log('hello'.at(-1));
Output
o
console.log('abc'.at(10));
Output
undefined

Notes

Returns undefined (not an empty string like `charAt`) for out-of-range indices. Operates on UTF-16 code units. Cleaner than `str[str.length - 1]`.

Browser & runtime support

EnvironmentSince version
chrome 92
firefox 90
safari 15.4
edge 92
node 16.6

See also