String.prototype.charAt
Returns the character at the specified index in a string
Syntax
string.charAt(index)Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | Zero-based index of the character |
Return Value
A string representing the character at the specified index
Examples
const str = 'Hello';
console.log(str.charAt(0)); // 'H'
console.log(str.charAt(4)); // 'o'const word = 'JavaScript';
for (let i = 0; i < word.length; i++) {
console.log(word.charAt(i));
}const str = 'abc';
console.log(str.charAt(10)); // '' (empty string)Understanding String.prototype.charAt
The String.prototype.charAt method in JavaScript returns the character at the specified index in a string. 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.charAt(index). It accepts 1 parameter: index. When called, it returns a string representing the character at the specified index. Understanding when and how to use charAt() helps you write more expressive, readable code.
Common use cases for String.prototype.charAt include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-charcodeat, string-codepointat, string-at, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for String.prototype.charAt 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
String.prototype.charCodeAtReturns an integer between 0 and 65535 representing the UTF-16 code unit at the given index
String.prototype.codePointAtReturns a non-negative integer that is the Unicode code point value at the given position
String.prototype.atTakes an integer value and returns the character at that index, supporting positive and negative integers
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.