JavaScript String codePointAt()
Examples
Get code point value at the first position in a string:
let text = "HELLO WORLD";
let code = text.codePointAt(0);
Try it Yourself »
Get the code point value at the second position:
let text = "HELLO WORLD";
let code = text.codePointAt(1);
Try it Yourself »
More examples below.
Definition and Usage
The codePointAt()
method returns the Unicode value at
an index (position) in a string.
The index of the first position is 0, the second is 1, ....
Difference Between charCodeAt() and 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 only codePointAt()
can return the full value of a Unicode value greather 0xFFFF (65535).
For more information about Unicode Character Sets, visit our Unicode Reference.
Syntax
string.codePointAt(index)
Parameters
Parameter | Description |
index | Optional. The index (position) in a the string. Default value = 0. |
Return Value
Type | Description |
Number | The code point value at the specified index.undefined if the index is invalid. |
More Examples
Get the code point value at the last position:
let text = "HELLO WORLD";
let code = text.charCodeAt(text.length-1);
Try it Yourself »
Get the code point value at the 15th position:
let text = "HELLO WORLD";
let code = text.charCodeAt(15);
Try it Yourself »
Browser Support
codePointAt()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
codePointAt()
is not supported in Internet Explorer 11 (or earlier).