您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月11日 09:53

原创 JavaScript String.charCodeAt() 函数详解

2395 次浏览 读完需要≈ 3 分钟

内容目录

charCodeAt()函数返回一个整数,该整数表示String对象中指定索引处的字符的Unicode编码。

该函数属于String对象,所有主流浏览器均支持该函数

语法

stringObject.charCodeAt( index )

参数

参数 描述
index Number类型指定的索引,从0开始。

返回值

charCodeAt()方法的返回值为Number类型,其返回值表示字符串对象指定索引处的字符的Unicode编码。

如果指定的索引超出字符串的有效范围,则返回NaN

示例&说明

var str = "CodePlayer";

document.writeln( str.charCodeAt( 0 ) ); // 67
document.writeln( str.charCodeAt( 4 ) ); // 80
document.writeln( str.charCodeAt( 12 ) ); //  NaN

str = "张三";
document.writeln( str.charCodeAt( 0 ) ); // 24352

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单