| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt | [Back] [Original] |
Get to know MDN better
charCodeAt() UTF-16 0 65535
charCodeAt() UTF-16 String.prototype.codePointAt()
const sentence = "The quick brown fox jumps over the lazy dog.";
const index = 4;
console.log(
`Character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(
index,
)}`,
);
// : "Character code 113 is equal to q"
charCodeAt(index)
0 65535 index UTF-16 index 0 str.length - 1 charCodeAt() NaN
0 str str.length - 1
Unicode 0 1114111 (0x10FFFF) charCodeAt() 65536 16 65535 charCodeAt(i) charCodeAt(i + 1) 2 codePointAt(i) Unicode UTF-16 Unicode
Unicode A 65
"ABC".charCodeAt(0); // returns 65
charCodeAt() Unicode
const str = "";
console.log(str.charCodeAt(0)); // 55362 d842 Unicode
console.log(str.charCodeAt(1)); // 57271 dfb7 Unicode
Unicode String.prototype.codePointAt()
const str = "";
console.log(str.codePointAt(0)); // 134071
:
charCodeAt() codePointAt() API codePointAt()
Unicode FAQ UTF-16 Unicode
// constants
const LEAD_OFFSET = 0xd800 - (0x10000 >> 10);
const SURROGATE_OFFSET = 0x10000 - (0xd800 << 10) - 0xdc00;
function utf16ToUnicode(lead, trail) {
return (lead << 10) + trail + SURROGATE_OFFSET;
}
function unicodeToUTF16(codePoint) {
const lead = LEAD_OFFSET + (codePoint >> 10);
const trail = 0xdc00 + (codePoint & 0x3ff);
return [lead, trail];
}
const str = "";
console.log(utf16ToUnicode(str.charCodeAt(0), str.charCodeAt(1))); // 134071
console.log(str.codePointAt(0)); // 134071
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.charcodeat |
Stringanchor()at()big()blink()bold()charAt()charCodeAt()codePointAt()concat()endsWith()fixed()fontcolor()fontsize()includes()indexOf()isWellFormed()italics()lastIndexOf()link()localeCompare()match()matchAll()normalize()padEnd()padStart()repeat()replace()replaceAll()search()slice()small()split()startsWith()strike()sub()substr()substring()sup()toLocaleLowerCase()toLocaleUpperCase()toLowerCase()toString()toUpperCase()toWellFormed()trim()trimEnd()trimStart()valueOf()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |