charAt()
The charAt() method helps to find the character in a string at a particular index.It takes a single parameter(index) to execute character corresponding to the particular index.
syntax
string.charAt(index);
Example-1
In the following example when index 9 is passed as a parameter to charAt() method, output p is displayed.
<html> <body> <p id="character"></p> <script> var string = "TUTORIALSPOINT AND TUTORIX"; var result = string.charAt(9) document.getElementById("character").innerHTML = result; </script> </body> </html>
output
p
Example-2
In the following example when index 11 is passed as a parameter, charAt() method executes character a as output
<html> <body> <script> var string = "Tutorix is a best e-learning platform"; var result = string.charAt(11) document.write(result); </script> </body> </html>
output
a