[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt [Back]  [Original]

String.prototype.codePointAt() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

String.prototype.codePointAt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 9.

String codePointAt() . UTF-16 .

In this article

const icons = "";

console.log(icons.codePointAt(1));
// Expected output: "9733"

js
codePointAt(index)

index

0 . undefined 0 .

index .

  • index 0 str.length - 1 , codePointAt() undefined .
  • index UTF-16 .
  • index UTF-16 .

. 0, str str.length - 1.

0 1114111(0x10FFFF). UTF-16 0 - 65535 . 16 . codePointAt() . UTF-16 , .

codePointAt()

js
"ABC".codePointAt(0); // 65
"ABC".codePointAt(0).toString(16); // 41

"".codePointAt(0); // 128525
"\ud83d\ude0d".codePointAt(0); // 128525
"\ud83d\ude0d".codePointAt(0).toString(16); // 1f60d

"".codePointAt(1); // 56845
"\ud83d\ude0d".codePointAt(1); // 56845
"\ud83d\ude0d".codePointAt(1).toString(16); // de0d

"ABC".codePointAt(42); // undefined

codePointAt()

( , ) codePointAt() .

js
const str = "\ud83d\udc0e\ud83d\udc71\u2764";

for (let i = 0; i < str.length; i++) {
  console.log(str.codePointAt(i).toString(16));
}
// '1f40e', 'dc0e', '1f471', 'dc71', '2764'

@@iterator for...of . codePointAt(0) .

js
for (const codePoint of str) {
  console.log(codePoint.codePointAt(0).toString(16));
}
// '1f40e', '1f471', '2764'

[...str].map((cp) => cp.codePointAt(0).toString(16));
// ['1f40e', '1f471', '2764']

Specification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.codepointat


Web Proxy Viewer  |  New URL  |  Original Page