如何返回一個指示字元的 Unicode 值的數字?
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>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP