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?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-14 08:17:02
forward
1036 people have browsed it

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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template