Home  >  Article  >  Web Front-end  >  How to convert javascript to ascii code

How to convert javascript to ascii code

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-06-11 17:18:394670browse

Conversion method: 1. Use the fromCharCode method to return a string according to the serial number value, the syntax "String.fromCharCode(num1, ..., numN)"; 2. Use the charCodeAt method to return an integer, the syntax "charCodeAt(index )".

How to convert javascript to ascii code

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Methods provided in JavaScript to convert ascii codes into corresponding letters, and convert corresponding letters into ascii codes:

String.fromCharCode() Static method according to the specification Returns a string with an ordinal value in Unicode encoding.

Syntax:

String.fromCharCode(num1, ..., numN)

String.prototype.charCodeAt()The method returns an integer between 0 and 65535, representing the UTF of the character at the index -16 code unit (In the case where the Unicode code unit represents a single UTF-16 code unit, the UTF-16 code unit matches the Unicode code unit. Otherwise, for example, in the case of Unicode code unit > 0x10000, only the Unicode proxy can be matched the first coding unit of the pair). If you want to get the whole point encoded value, use codePointAt().

Syntax:

str.charCodeAt(index)

index

An integer greater than or equal to 0 and less than the length of the string. If not a numeric value, defaults to 0.

"ABC".charCodeAt(0) // returns 65

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to convert javascript to ascii code. For more information, please follow other related articles on the PHP Chinese website!

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