JavaScript .charAt()
Published Jun 23, 2021Updated Jun 28, 2023
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 to be returned.
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
Codebyte Example
The following is runnable, and demonstrates the use of the .charAt() method:
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours