Widely availableA small readability improvement that is worth using when you often read the last or near-last character.

Overview

String.prototype.at() returns the character at a given index and supports negative indexes from the end. It is a clearer alternative to repeated length arithmetic for tail access.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
92
92
90
15.4
92
15.4
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
const str = 'Hello';

str.at(0);   // 'H'
str.at(-1);  // 'o'
str.at(-2);  // 'l'

Live demo

end. Character Read

At(-1) Use, string. last. 1character read..

PreviewFullscreen

specificposition. Character

positivenegative. index in character to akses..

PreviewFullscreen

saroge-tpea(emoji). note

At is co-dyunitbe-s., emoji. to note that main..

PreviewFullscreen

Use cases

  • Reading the last character

    Use at(-1) for file extensions, suffix markers, or quick boundary checks.

  • Tail-oriented parsing

    Negative indexes keep string parsing code shorter when you need the end of a token or input.

Cautions

  • Out-of-range access returns undefined, so guard against missing values when later code assumes a string.
  • at() still works on UTF-16 code units, so complex emoji and grapheme clusters may need a different API.

Accessibility

  • If character inspection affects validation or formatting, make the resulting feedback visible and understandable to users.

Powered by web-features