What is charAt() in JavaScript?

The charAt() method in Java returns a string character from a specified index.

Syntax

The syntax of this method is as follows:


string.charAt(index)

Parameters

The charAt() function takes one integer parameter that is the index from which the character needs to be extracted.

Return value

The return value is a character from the specified index.

Code

In the code below, the character E is extracted from the string s with the help of the charAt() method.

// extacting the character from 11th index of the string
class string {
public static void main( String args[] ) {
String s = "Welcome to Educative";
char ch = s.charAt(11);
System.out.println(ch);
}
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources