charAt 方法 (String)
返回指定索引位置处的字符。
语法
strObj. charAt(index)
参数
strObj
必要参数。任何String对象或字符串。
index
必要参数。所需字符的从零开始的索引。
备注
chatAt方法返回一个字符值,该字符值等于指定index位置的字符。一个字符串中的第一个字符位于索引位置0,第二个字符串位于索引位置1,依此类推。超出范围的index返回空字符串。
示例
下面的示例演示了charAt
方法的用法:
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; document.write(str.charAt(str.length - 1)); // Output: Z
必备条件
在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。此外,也在应用商店应用(Windows 8 和 Windows Phone 8.1)中受支持。请参阅版本信息。
Applies To: String Object