Home >Web Front-end >HTML Tutorial >How to return a number representing the Unicode value of a character?

How to return a number representing the Unicode value of a character?

WBOY
WBOYforward
2023-09-14 08:17:02999browse

How to return a number representing the Unicode value of a character?

# The charCodeAt() method returns a number representing the Unicode value of the character at the given index. Unicode code points range from 0 to 1,114,111. The first 128 Unicode code points directly match the ASCII character encoding.

charCodeAt(index) supports the following parameters:

  • index - an integer between 0 and the length of the string minus 1; if not specified, Default is 0.

Example

You can try running the following code to return a number representing the Unicode value of a character:

<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>

The above is the detailed content of How to return a number representing the Unicode value of a character?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete