extraction

String.prototype.codePointAt

Returns the full Unicode code point (0–0x10FFFF) starting at the given position, correctly combining surrogate pairs. Added in ES2015 as the Unicode-safe counterpart to charCodeAt.

str.codePointAt(position)

Parameters

Parameter Purpose
position Zero-based index (default 0)
returns Integer code point, or undefined if out of range

Examples

console.log('A'.codePointAt(0));

Prints 65

console.log('😀'.codePointAt(0));

Prints 128512 (0x1F600)

console.log('😀'.codePointAt(1));

Prints 56832 (trailing surrogate on its own)

console.log('abc'.codePointAt(10));

Prints undefined

Gotcha

position addresses UTF-16 code units, so iterating with i++ still lands inside surrogate pairs — use for...of for code point iteration.

Related methods

← All JS string methods · JS array methods