charAt String JavaScript

The JavaScript string charAt() method retrieves the char value present at the specified index. If n is the size of the string then the index can be from 0 to n-1.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
String.charAt(index)
String.charAt(index)
String.charAt(index) 

Parameters:
index: It represents the specified position of a character.

Return:
Char value present at the specified index.

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
var hello ="HELLO WORLD!";
document.writeln(hello.charAt(11));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> var hello ="HELLO WORLD!"; document.writeln(hello.charAt(11)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
var hello ="HELLO WORLD!";
document.writeln(hello.charAt(11));
</script>
</body>
</html>

Example 2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
var stringObj = 'Best tutorial wesite';
document.write("The character at index 0 is " + stringObj.charAt());
document.write("<br>");
document.write("The character at index 0 is " + stringObj.charAt(0));
document.write("<br>");
document.write("The character at index 1 is " + stringObj.charAt(1));
document.write("<br>");
document.write("The character at index 2 is " + stringObj.charAt(2));
document.write("<br>");
document.write("The character at index 100 is " + stringObj.charAt(100));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> var stringObj = 'Best tutorial wesite'; document.write("The character at index 0 is " + stringObj.charAt()); document.write("<br>"); document.write("The character at index 0 is " + stringObj.charAt(0)); document.write("<br>"); document.write("The character at index 1 is " + stringObj.charAt(1)); document.write("<br>"); document.write("The character at index 2 is " + stringObj.charAt(2)); document.write("<br>"); document.write("The character at index 100 is " + stringObj.charAt(100)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
var stringObj = 'Best tutorial wesite';
document.write("The character at index 0 is " + stringObj.charAt());
document.write("<br>");
document.write("The character at index 0 is " + stringObj.charAt(0));
document.write("<br>");
document.write("The character at index 1 is " + stringObj.charAt(1));
document.write("<br>");
document.write("The character at index 2 is " + stringObj.charAt(2));
document.write("<br>");
document.write("The character at index 100 is " + stringObj.charAt(100));
</script>
</body>
</html>