.charAt()

Returns a single character at the specified index of a string.

Syntax

string.charAt(index);

index is a required parameter representing the index of the character you want to return.

Examples

Find the first character in a string:

const greeting = 'Hello World';
const firstLetter = greeting.charAt(0);
console.log(firstLetter);
// Output: H

Find the last character in a string:

const greeting = 'Hello World';
const lastLetter = greeting.charAt(greeting.length - 1);
console.log(lastLetter);
// Output: d

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy

Contributors