如何返回一个数字,表示字符的 Unicode 值?
charCodeAt() 方法可返回一个数字表示给定 index 处的字符的 Unicode 值。Unicode 代码点范围从 0 到 1,114,111。前 128 个 Unicode 代码点直接匹配于 ASCII 字符编码。
charCodeAt(index) 支持以下参数−
- index − 0 与字符串长度减 1 之间的整数;如果未指定,则默认为 0。
示例
你可以尝试运行以下代码来返回一个数字表示字符的 Unicode 值−
<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>
<body>
<script>
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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP