charAt 方法
更新:2007 年 11 月
傳回 String 物件中指定索引上的字元。
function charAt(index : Number) : String
引數
- index
必要項。必要字元以零起始的索引。有效值介於 0 到字串長度減 1 之間。
備註
charAt 方法所傳回的字元值與所指定 index 中的字元相同。字串中第一個字元的索引是 0,第二個字元的索引是 1,依此類推。有效範圍以外的 index 值會傳回空字串。
範例
以下範例說明如何使用 charAt 方法:
function charAtTest(n){
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Initialize variable.
var s; // Declare variable.
s = str.charAt(n - 1); // Get correct character
// from position n – 1.
return(s); // Return character.
}