LoginSignup
13
11

More than 5 years have passed since last update.

charCodeAtとfromCharCodeを試してみよう

Posted at

はじめに

String.prototype.charCodeAtとString.fromCharCodeを試してみました。

String.prototype.charCodeAtはUnicodeを10進数に変換するStringのメソッドです。

String.fromCharCodeはUnicodeの値の数のシーケンスを文字列に変換するStringの静的メソッドです。

How

Node.jsでもブラウザでも確認できます。

% node
> "ABC".charCodeAt(0)
65
> "ABC".charCodeAt(1)
66
> "ABC".charCodeAt(2)
67
> "未来".charCodeAt(0)
26410
> "未来".charCodeAt(1)
26469
> "未来".charCodeAt(2)
NaN
> "未来".charCodeAt(-1)
NaN
> String.fromCharCode(65,66,67)
'ABC'
> String.fromCharCode(26410)
''
> String.fromCharCode(26411)
''
> String.fromCharCode(26412)
''
> String.fromCharCode(26413)
''
> String.fromCharCode(26414)
''
> String.fromCharCode(26415)
''
> String.fromCharCode(26416)
''
> String.fromCharCode(26417)
''
> String.fromCharCode(26418)
''
> String.fromCharCode(26419)
''
> String.fromCharCode(26420)
''

参照URL

13
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11