The charAt() String Method

By: Dusty Arlia
Published on Monday, April 1, 2013, 08:14 PM
Last Updated on Wednesday, July 15, 2015 at 6:45 PM
Total Updates: 2

Strings include several methods. The charAt() method returns the character at the position you request. Here is an example:

var first_name = "Dusty";

The string Dusty invokes the charAt() method using dot-syntax. This method returns the first character in the string Dusty (in the "0" position). This example prints D to the screen.

Here is another example returning the second character and saving it to the variable second_character:

var second_character = first_name.charAt(1);

This example prints u to the screen.