扫码一下
查看教程更方便
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