Favorites

JavaScript String.prototype.at() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.at()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The at() method returns the character at a given index of a string, accepting negative numbers to count back from the end.

Description

The at() method returns the character at an index. Negative indexes count from the end, so str.at(-1) is the last character. Out-of-range indexes return undefined, whereas charAt() returns an empty string.

Because at() works with UTF-16 code units, emoji and some other characters made of two code units come back as one half of a pair rather than the whole character. Spreading the string into an array first, [...str].at(-1), returns whole code points instead.

The same method exists on arrays and typed arrays, so you can use one consistent way to read from the end of all of them. Non-integer indexes are truncated towards zero, and a missing index is treated as 0.

Syntax

string.at(index)

Parameters

  • indexThe position of the character. Negative numbers count back from the end.

Return Value

A string containing the single UTF-16 code unit at that position, or undefined if the index is out of range.

Example

const word = 'JavaScript';
console.log(word.at(0));
console.log(word.at(-1));
console.log(word.at(20));

Browser Support

The following information will show you the current browser support for the String.prototype.at() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee