String codePointAt() and fromCodePoint()
codePointAt() は String 値のメソッドで、指定されたインデックスから始まる文字の Unicode コードポイント値である非負の整数を返します。インデックスは Unicode コードポイントではなく、UTF-16 コード単位に基づくことに注意してください。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 41 | 12 | 29 | 9 | 41 | 9 | |
| ビルトインオブジェクト | ||||||
| String.fromCodePoint() 静的メソッドは指定されたコードポイントの並びを使って生成された文字列を返します。 | 41 | 12 | 29 | 9 | 41 | 9 |
基本構文
JAVASCRIPT
'😀'.codePointAt(0); // 128512
String.fromCodePoint(128512); // '😀'
// charCodeAt cannot handle surrogate pairs correctly
'😀'.charCodeAt(0); // 55357 (upper surrogate only) ライブデモ
co-point from generate
Number(co-point) from character generate..128512 input and emoji that display..
プレビュー全画面表示
saroge-tpea. comparison
CharCodeAt (16bit) and codePointAt (Unicode). Difference inspect it..
プレビュー全画面表示
実務での使いどころ
-
String codePointAt() and fromCodePoint() の活用
codePointAt() は String 値のメソッドで、指定されたインデックスから始まる文字の Unicode コードポイント値である非負の整数を返します。
注意点
- 特になし。すべての主要ブラウザで安定して動作する。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。