1. charcodeat ()
Convert characters into code;
var str="Hello world!"document.write(str.charCodeAt(1))
- 'Cjk ': ['u4e00', 'u9fa5'], // Chinese Character [1-Example]
- 'Num': ['u0030', 'u0039 '], // number [0-9]
- 'Lal': ['u0061 ', 'u007a'], // lowercase letter [A-Z]
- 'Ual': ['u0041', 'u005a '], // uppercase letter [A-Z]
- 'Asc': ['u0020', 'u007e '] // ASCII visual character
2. fromcharcode ()
Convert code into characters
Definition and usage
Fromcharcode () accepts a specified Unicode value and returns a string.
Syntax
String.fromCharCode(numX,numX,...,numX)
| Parameters |
Description |
| Numx |
Required. One or more Unicode values, that is, the Unicode encoding of the characters in the string to be created. |
Tips and comments
Note: This method is a static string method. Each character in a string is specified by a separate numeric unicode encoding.
It cannot be used as a string object created by you. Therefore, its syntax should be string. fromcharcode (), rather than mystringobject. fromcharcode ().
Instance
In this example, "hello" and "ABC" are output based on UNICODE ":
<script type="text/javascript">document.write(String.fromCharCode(72,69,76,76,79))document.write("<br />")document.write(String.fromCharCode(65,66,67))</script>
Output of the above Code:
HELLOABC
3. Differences between charcodeat () and charat ()
Charcodeat (I) returns the Unicode encoding of characters at the specified position.
Charat (I) returns the character at the specified position.