JavaScript String codePointAt()
Examples
Get code point value at the first position in a string:
let code = text.codePointAt(0);
Get the code point value at the second position:
let code = text.codePointAt(1);
More examples below.
Description
ThecodePointAt() method returns the Unicode value atan 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 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. 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 code = text.charCodeAt(text.length-1);
Get the code point value at the 15th position:
let code = text.charCodeAt(15);
Browser Support
codePointAt() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers sinceJune 2017:
| Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |

