charcodeat()方法返回一个数字,表示给定索引处字符的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>
以上就是如何返回一个表示字符的unicode值的数字?的详细内容。