To express, for example, the character U+10400 in JavaScript, I use \"\\uD801\\uDC00\"
or String.fromCharCode(0xD801) + String.fromCharCode(0xDC00)
How do I find
0xD801
and0xDC00
from0x10400
?
JavaScript uses UCS-2 internally. That’s why String#charCodeAt()
doesn’t work the way you’d want it to.
If you want to get the code point of every Unicode character (including non-BMP characters) in a string, you could use Punycode.js’s utility functions to convert between UCS-2 strings and UTF-16 code points:
// String#charCodeAt() replacement that only considers full Unicode characters
punycode.ucs2.decode('