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.


Description

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, ....

See Also:

The charCodeAt() Method

The charAt() Method

The indexOf() Method

The lastIndexOf() Method

Unicode

For more information about Unicode Character Sets, visit our Unicode Reference.


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
indexOptional.
The index (position) in a the string.
Default value = 0.

Return Value

Type Description
NumberThe 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 since June 2017:

Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 Apr 2017 Jun 2017 Sep 2016 Jun 2016

codePointAt() is not supported in Internet Explorer.


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.