| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/charAt | [Back] [Original] |
Get to know MDN better
charAt() String UTF-16
charAt() UTF-16 Unicode String.prototype.codePointAt() String.fromCodePoint()
const sentence = "The quick brown fox jumps over the lazy dog.";
const index = 4;
console.log(`The character at index ${index} is ${sentence.charAt(index)}`);
// : "The character at index 4 is q"
charAt(index)
index 1 UTF-16 index charAt()
0 str str.length - 1
Unicode 0 1114111 (0x10FFFF) charAt() 65536 16 65535 charAt(i) charAt(i + 1) 2 codePointAt(i) String.fromCodePoint() Unicode UTF-16 Unicode
charAt() index index charAt() index undefined `"Brave new world"``
const anyString = "Brave new world";
console.log(`The character at index 0 is '${anyString.charAt()}'`);
// No index was provided, used 0 as default
console.log(`The character at index 0 is '${anyString.charAt(0)}'`);
console.log(`The character at index 1 is '${anyString.charAt(1)}'`);
console.log(`The character at index 2 is '${anyString.charAt(2)}'`);
console.log(`The character at index 3 is '${anyString.charAt(3)}'`);
console.log(`The character at index 4 is '${anyString.charAt(4)}'`);
console.log(`The character at index 999 is '${anyString.charAt(999)}'`);
The character at index 0 is 'B' The character at index 0 is 'B' The character at index 1 is 'r' The character at index 2 is 'a' The character at index 3 is 'v' The character at index 4 is 'e' The character at index 999 is ''
charAt() Unicode
const str = "";
console.log(str.charAt(0)); // "\ud842" Unicode
console.log(str.charAt(1)); // "\udfb7" Unicode
Unicode String.prototype.codePointAt() Unicode Unicode
const str = "";
console.log(String.fromCodePoint(str.codePointAt(0))); // ""
console.log([...str][0]); // ""
:
charAt() API API
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.charat |
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 |