JavaScript入門講座

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
関連メソッド説明
fromcharcodeユニコードを文字に変換