Home > Stringオブジェクト > charCodeAtメソッド
charCodeAtメソッド
charCodeAtメソッドはN-1番目の文字をUnicodeコードに変換する。
書式 | charCodeAt(N) |
戻り値 | N-1番目の文字をUnicodeコードに変換して返す |
引数 | N | 数値を指定する |
使用例 | 文字をUnicodeコードに変換して取得する。 |
var str = 'ABCDEF';
document.write(str.charCodeAt(0) , '<br />'); //65
document.write(str.charCodeAt(1) , '<br />'); //66
document.write(str.charCodeAt(2) , '<br />'); //67
document.write(str.charCodeAt(3) , '<br />'); //68
document.write(str.charCodeAt(4) , '<br />'); //69
document.write(str.charCodeAt(5) , '<br />'); //70
document.write(str.charCodeAt(6)); //NaN