Get Character From String Method

The Get Character From String method returns the character that resides at a specific location in a string. The length of this character is 1.

To get the first character in a string, you use position 0. For example:

var string1 = "a string";
var firstchar = string1.charAt(0);

To get the last character in a string, you use length minus 1. For example:

var lastchar = string1.charAt(string1.length - 1);

If the value in the position argument is not between 0 and the value of stringVar.length minus 1, then this method returns an empty string.

Format

stringVar.charAt(position)

The following table describes the arguments for the Get Character From String method.

Argument Description

position

An integer that describes the position in the string of the character that this method returns. The position of the first character in the string is 0.