charCodeAt() मेथड दिए गए इंडेक्स पर कैरेक्टर के यूनिकोड मान को दर्शाने वाली संख्या लौटाता है। यूनिकोड कोड पॉइंट 0 से 1,114,111 तक होते हैं। पहले 128 यूनिकोड कोड पॉइंट ASCII कैरेक्टर एन्कोडिंग का सीधा मिलान हैं।
charCodeAt(index) द्वारा निम्न पैरामीटर समर्थित है:
- index - 0 और स्ट्रिंग की लंबाई से 1 कम के बीच का पूर्णांक; यदि अनिर्दिष्ट है, तो डिफ़ॉल्ट 0 है।
उदाहरण
कैरेक्टर के यूनिकोड मान को दर्शाने वाली संख्या लौटाने के लिए निम्न कोड चलाएं:
<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>