Javascript 中的 charAt()函数

首页 / JavaScript入门教程 / Javascript 中的 charAt()函数

charat()是从指定索引返回字符的方法。

charAt() - 语法

使用以下语法查找特定索引处的字符。

string.charAt(index);

index  - 小于字符串长度的0到1之间的整数。

charAt() - 返回值

返回指定索引中的字符。

无涯教程网

charAt() - 示例

<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 

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

OpenResty从入门到实战 -〔温铭〕

Elasticsearch核心技术与实战 -〔阮一鸣〕

NLP实战高手课 -〔王然〕

Redis核心技术与实战 -〔蒋德钧〕

技术管理案例课 -〔许健〕

郭东白的架构课 -〔郭东白〕

结构写作力 -〔李忠秋〕

LangChain 实战课 -〔黄佳〕

程序员职业规划手册 -〔雪梅〕

好记忆不如烂笔头。留下您的足迹吧 :)