# JavaScript String.prototype.charAt() - Char At Explained with Examples

**URL:** <https://forum.freecodecamp.org/t/javascript-string-prototype-charat-char-at-explained-with-examples/15932>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [June 30, 2016, 6:10pm UTC](https://forum.freecodecamp.org/t/javascript-string-prototype-charat-char-at-explained-with-examples/15932 "2016-06-30T18:10:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [June 30, 2016, 6:10pm UTC](https://forum.freecodecamp.org/t/javascript-string-prototype-charat-char-at-explained-with-examples/15932/1 "2016-06-30T18:10:18Z")

</div>

The `charAt()` method returns the specified character from a string.

## Syntax

```auto
str.charAt(index)

```

## Parameters

**index**

An integer between 0 and 1-less-than the length of the string.

## Description

Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string called `stringName` is `stringName.length - 1` . If the index you supply is out of range, JavaScript returns an empty string.

## Examples

```auto
var anyString = 'Brave new world';

console.log("The character at index 0 is '" + anyString.charAt(0) + "'"); // 'B'
console.log("The character at index 1 is '" + anyString.charAt(1) + "'"); // 'r'
console.log("The character at index 2 is '" + anyString.charAt(2) + "'"); // 'a'
console.log("The character at index 3 is '" + anyString.charAt(3) + "'"); // 'v'
console.log("The character at index 4 is '" + anyString.charAt(4) + "'"); // 'e'
console.log("The character at index 999 is '" + anyString.charAt(999) + "'"); // ''

var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write(str.charAt(str.length - 1));

// Output: Z

```

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [August 7, 2017, 1:46am UTC](https://forum.freecodecamp.org/t/javascript-string-prototype-charat-char-at-explained-with-examples/15932/2 "2017-08-07T01:46:53Z")

</div>

Closed on August 7, 2017, 1:46am UTC


