charat()是从指定索引返回字符的方法。
使用以下语法查找特定索引处的字符。
string.charAt(index);
index - 小于字符串长度的0到1之间的整数。
返回指定索引中的字符。
<html> <head> <title>JavaScript String charAt() Method</title> </head> <body> <script type="text/javascript"> var str=new String( "This is string" ); document.writeln("str.charAt(0) is:" + str.charAt(0)); document.writeln("<br />str.charAt(1) is:" + str.charAt(1)); document.writeln("<br />str.charAt(2) is:" + str.charAt(2)); document.writeln("<br />str.charAt(3) is:" + str.charAt(3)); document.writeln("<br />str.charAt(4) is:" + str.charAt(4)); document.writeln("<br />str.charAt(5) is:" + str.charAt(5)); </script> </body> </html>
运行上面代码输出
链接:https://www.learnfk.comhttps://www.learnfk.com/javascript/string-charat.html
来源:LearnFk无涯教程网
str.charAt(0) is:T str.charAt(1) is:h str.charAt(2) is:i str.charAt(3) is:s str.charAt(4) is: str.charAt(5) is:i
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)