var str = "I learn JavaScript";
// The index starts at zero:
alert( str.charAt(0) ); // returns "I"
Tip: remember that charAt(1) returns the *second* character, because indices start at 0.
var str = "I learn JavaScript";
alert( str.charAt( str.length-1 ) ); // returns "t"
If you pass an index greater than the length of the string, JavaScript will return an empty string.$str = 'I learn PHP';
echo $str{3}; // returns 'e'
Sister method: charCodeAt() returns the Unicode value for the character found at that index. From 0 to 128 (mostly Latin alphabet), these codes correspond to ASCII encoding. And fromCharCode() takes Unicode codes as arguments, and returns the corresponding string.