Get code point value at the first position in a string:
let text = "HELLO WORLD";
let code = text.codePointAt(0);
Get the code point value at the second position:
let text = "HELLO WORLD";
let code = text.codePointAt(1);
More examples below.
DescriptionThe 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.
Syntaxstring.codePointAt(index)
Parameters Parameter Description index Optional.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);
Get the code point value at the 15th position:
let text = "HELLO WORLD";
let code = text.charCodeAt(15);
codePointAt()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
ChromeTrack your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4