String codePointAt() and fromCodePoint()
String.prototype.codePointAt() は指定位置の Unicode コードポイントを返し、String.fromCodePoint() はコードポイントから文字列を生成します。サロゲートペア(絵文字等)を正しく扱えます。
概要
String.prototype.codePointAt() は指定位置の Unicode コードポイントを返し、String.fromCodePoint() はコードポイントから文字列を生成します。サロゲートペア(絵文字等)を正しく扱えます。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| 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() の活用
Unicode コードポイントを扱うメソッド。サロゲートペアを正しく処理できる。
注意点
- 特になし。すべての主要ブラウザで安定して動作する。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。
参考リンク
Powered by web-features