教程 > javascript 教程 > 阅读:16

javascript string charcodeat 方法——迹忆客-ag捕鱼王app官网

返回 javascript string 对象


定义

charcodeat() 方法可返回指定位置的字符的 unicode 编码,返回值是 0 - 65535 之间的整数,表示给定索引处的 utf-16 代码单元。

字符串中第一个字符的位置为 0, 第二个字符位置为 1,以此类推。

语法

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

string.charcodeat(index);

参数

index - 必需。表示字符串中某个位置的数字,即字符在字符串中的下标。

返回值

返回在指定的位置的字符的 unicode 编码。

浏览器支持

所有主流浏览器都支持 charcodeat 方法。

示例


   
      javascript string charcodeat() method
   
   
      
            
   

输出结果:

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

返回 javascript string 对象

查看笔记

扫码一下
查看教程更方便
网站地图