JavaScript (ES2026) reference · String Methods

JavaScript String at() Method

Return the character at an index, where negative indexes count from the end: str.at(-1) is the last character.

JavaScript (ES2026) Since ES2022

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.at(index)

Parameters

ParameterDescription
index Position; negative values count back from the end.

Return value

A one-character string, or undefined if the index is out of range.

Examples

Positive and negative indexesTry it yourself
const word = "camel";
console.log(word.at(0), word.at(-1), word.at(10));

Output

c l undefined
The last characterTry it yourself
const file = "report.pdf";
console.log(file[file.length - 1]); // the old way
console.log(file.at(-1));          // the same, shorter

Output

f
f

Version history

VersionChange
JavaScript ES2022Added

Was this page helpful?