Return the Unicode of the first character in a string (the Unicode value for "H"):
var n = str.charCodeAt(0);
More "Try it Yourself" examples below.
Definition and Usage
The charCodeAt() method returns the Unicode of the character at the specified index in a string.
The index of the first character is 0, the second character 1, and so on.
Tip: You can use the charCodeAt() method together with the length property to return the Unicode of the last character in a string. The index of the last character is -1, the second last character is -2, and so on (See Example below).
Tip: For more information about Unicode Character Sets, visit our HTML Character Sets reference.
|index||Required. A number representing the index of the character you want to return|
|Return Value:||A Number, representing the unicode of the character at the specified index.
Note: This method returns "NaN" if there is no character at the specified index, or if the index is less than "0".
Return the Unicode of the last character in a string (the Unicode value for "D"):
var n = str.charCodeAt(str.length-1);