JS: String.prototype.charCodeAt
str.charCodeAt(index)
-
Return a integer that's the
String Code Unit
at index
index in str.
"abc".charCodeAt(0) === 97
If the string contains NON-ASCII character, result may not be what you expect.
console.log("😂".charCodeAt(0) === 55357); console.log("😂".charCodeAt(0) === 0xd83d); /* 😂 name: FACE WITH TEARS OF JOY codepoint decimal: 128514 codepoint hexadecimal: 1f602 UTF-8 encoding: F0 9F 98 82 UTF-16 encoding: D8 3D DE 02 since the char 😂 in UTF-16 encoding is D8 3D DE 02, so the first byte in hexadecimal is D83D, which in decimal is 55357. therefore its charCode at 0th index is 55357. */
JavaScript, String, Char, Encoding, Hexadecimal
JS String.prototype
- JS: String.prototype.constructor
- JS: String.fromCharCode
- JS: String.prototype.concat
- JS: String.prototype.repeat
- JS: String.prototype.trim
- JS: String.prototype.trimStart
- JS: String.prototype.trimEnd
- JS: String.prototype.padStart
- JS: String.prototype.padEnd
- JS: String.prototype.slice
- JS: String.prototype.substring
- JS: String.prototype.substr
- JS: String.prototype.indexOf
- JS: String.prototype.lastIndexOf
- JS: String.prototype.includes
- JS: String.prototype.startsWith
- JS: String.prototype.endsWith
- JS: String.prototype.search
- JS: String.prototype.match
- JS: String.prototype.matchAll
- JS: String.prototype.replace
- JS: String.prototype.split
- JS: String.prototype.toLowerCase
- JS: String.prototype.charAt
- JS: String.prototype.charCodeAt
- JS: String.prototype.codePointAt