1、描述
此方法返回指示给定索引处的字符的Unicode
值的数字。
Unicode Code
点的范围从0到1,114,111。第一128个Unicode代码点是ASCII字符编码的直接匹配。 charCodeAt()
始终返回小于65,536的值。
2、语法
使用以下语法查找特定索引处的字符代码:
string.charCodeAt(index);
3、参数
index:0
到1
之间的整数小于字符串的长度; 如果未指定,则默认为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
免责声明:以上内容(如有图片或视频亦包括在内)有转载其他网站资源,如有侵权请联系删除
为你推荐
-
TV动画《入间同学入魔了》第三季制作确认 将于10月播出
根据西修原作制作的TV动画《入间同学入魔了》第三季宣布了将于2022年10月播出的消息。本作的宣传图也一并公开。在这次的新宣传图上,可以看到主人公入间和新角色巴巴托斯的样子。 《入间同学入魔了》作品讲述了被父母卖给了恶魔的14岁少年铃木入间在魔界学园生活的故事。TV动画第一季和第二季分别在20
-
华硕Z690主板发布 12代酷睿致胜神装
-
S9:ISGvsSPY 欧洲蛇咬下大白鲨赢得小组第一名!
{@SYS-PAGE-SPLIT@}
-
韩国画师冷门动物拟人作品
-
《幻塔》开服福利少?别被骗了 游戏里藏着大量白给的好东西
-
克苏鲁+伊藤润二《恐怖世界》2023年夏季推出1.0版 并登陆主机
-
iPhone15ProMax预计售价2万块,网曝有这些改变
加载中...