Share via


charCodeAt 方法

更新:2007 年 11 月

傳回的整數代表在 String 物件所指定位置之字元的 Unicode 編碼。

 function charCodeAt(index : Number) : String

引數

  • index
    必要項。必要字元以零起始的索引。有效值介於 0 到字串長度減 1 之間。

備註

字串中第一個字元的索引是 0,第二個字元的索引是 1,依此類推。

如果指定的 index 位置上沒有任何字元,即傳回 NaN

範例

以下範例說明如何使用 charCodeAt 方法。

function charCodeAtTest(n){
  var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //Initialize variable.
  var n;                                  //Declare variable.
  n = str.charCodeAt(n - 1);              //Get the Unicode value of the
                                          // character at position n.
  return(n);                              //Return the value.
}

需求

5.5 版

套用至:

String 物件

請參閱

參考

fromCharCode 方法