JavaScript String charCodeAt()
Examples
Get the Unicode of the first character in a string:
let code = text.charCodeAt(0);
Get the Unicode of the second:
let code = text.charCodeAt(1);
More examples below.
Description
ThecharCodeAt() method returns the Unicode of the characterat a specified index (position) in a string.
The index of the first character is 0, the second is 1, ....
The index of the last character is string length - 1 (See Examples below).
See also thecharAt() method.
charCodeAt() vs codePointAt()
charCodeAt() is UTF-16,codePointAt()is Unicode.
charCodeAt() returns a number between 0 and 65535.
Both methods return an integer representing the UTF-16 code of a character,but onlycodePointAt() can return the full value of a Unicode value greather 0xFFFF (65535).
For more information about Unicode Character Sets, visit ourUnicode Reference.
Syntax
Parameters
| Parameter | Description |
| index | Optional. A number. The index (position) of a character. Default value = 0. |
Return Value
| Type | Description |
| A number | The Unicode of the character at the specified index. NaN if the index is invalid. |
More Examples
Get the Unicode of the last character in a string:
let code = text.charCodeAt(text.length-1);
Get the Unicode of the 15th character:
let code = text.charCodeAt(15);
Browser Support
charCodeAt() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |

