String.prototype.at
Takes an integer value and returns the character at that index, supporting positive and negative integers
Syntax
string.at(index)Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | Zero-based index. Negative values count from the end |
Return Value
The character at the given index, or undefined
Examples
const str = 'Hello';
console.log(str.at(0)); // 'H'
console.log(str.at(-1)); // 'o'const word = 'JavaScript';
console.log(word.at(-3)); // 'i'function lastChar(s: string) {
return s.at(-1);
}
console.log(lastChar('world')); // 'd'Understanding String.prototype.at
The String.prototype.at method in JavaScript takes an integer value and returns the character at that index, supporting positive and negative integers. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.
The method signature is string.at(index). It accepts 1 parameter: index. When called, it returns the character at the given index, or undefined. Understanding when and how to use at() helps you write more expressive, readable code.
Common use cases for String.prototype.at include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-charat, array-at, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for String.prototype.at is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More String Methods
Other methods in the String object
Related Tools
More String Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.