深圳幻海软件技术有限公司欢迎您!

幻海优品

JavaScript(JS) string.charCodeAt(index)

1、描述

此方法返回指示给定索引处的字符的Unicode值的数字。

Unicode Code点的范围从0到1,114,111。第一128个Unicode代码点是ASCII字符编码的直接匹配。 charCodeAt()始终返回小于65,536的值。

2、语法

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

string.charCodeAt(index);

3、参数

index01之间的整数小于字符串的长度; 如果未指定,则默认为0

4、返回值

返回指示给定索引处的字符的Unicode值的数字。如果给定的索引不在0到1之间的介于0到1之间,则返回NaN

5、使用示例

<html>   <head>      <title>JavaScript String charCodeAt() Method</title>   </head>      <body>         <script type = "text/javascript">         var str = new String( "This is string" );         document.write("str.charCodeAt(0) is:" + str.charCodeAt(0));          document.write("<br />str.charCodeAt(1) is:" + str.charCodeAt(1));          document.write("<br />str.charCodeAt(2) is:" + str.charCodeAt(2));          document.write("<br />str.charCodeAt(3) is:" + str.charCodeAt(3));          document.write("<br />str.charCodeAt(4) is:" + str.charCodeAt(4));          document.write("<br />str.charCodeAt(5) is:" + str.charCodeAt(5));       </script>         </body></html>

6、输出

str.charCodeAt(0) is:84str.charCodeAt(1) is:104str.charCodeAt(2) is:105str.charCodeAt(3) is:115str.charCodeAt(4) is:32str.charCodeAt(5) is:105 

免责声明:以上内容(如有图片或视频亦包括在内)有转载其他网站资源,如有侵权请联系删除