String.prototype.charAt() Method in String Class of Javascript Syntax with Examples
2822 Views
Usage
charAt(int index) returns character at the index position of the string.
Syntax
String.charAt(int index);
index - specify which position character needs to take from the string. index is starting from zero.
Example
var userName = "gopalakrishnan";
//Returns chartacter at 2 index which means `p`.
var charAt2 = userName.charAt(2);
document.write("character is "+charAt2+" at 2.");
//No characters at 54 index So returns empty character
var charAt54 = userName.charAt(54);
document.write("character is "+charAt54+" at 54.");