JavaScript String charAt() Method

The JavaScript string charAt() method is used to find out a char value present at the specified index in a string.

The index number starts from 0 and goes to n-1, where n is the length of the string. The index value can't be a negative, greater than or equal to the length of the string.

Syntax

The charAt() method is represented by the following syntax:

Parameter

index - It represent the position of a character.

Returns

A char value

JavaScript String charAt() Method Example

Let's see some examples of charAt() method.

Example 1

Let's see a simple example to print a character.

Test it Now

Output:

t

Example 2

In this example, we will not pass an index value.

Test it Now

Output:

J

Example 3

In this example, we will print the last character.

Test it Now

Output:

t





Latest Courses