Home > Web Front-end > JS Tutorial > body text

How to convert javascript to ascii code

醉折花枝作酒筹
Release: 2021-06-15 09:13:53
Original
4683 people have browsed it

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

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

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

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

Related labels:
source:php.cn
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