Home > Article > Web Front-end > How to convert letters to numbers in javascript
In JavaScript, you can use the charCodeAt() method to convert letters into numbers. The syntax format is "String object.charCodeAt (the subscript of the character in the string)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Method: Convert characters to ascii code: use charCodeAt();
Convert ascii code to characters: use fromCharCode();
Example:
Convert letters Convert numbers into numbers:
var str='A'; str.charCodeAt()
Convert numbers into letters:
var num=65 ; String.fromCharCode(num);
获取小写字母a的代码: a===>String.fromCharCode(0x60+1); z===>String.fromCharCode(0x60+26)
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to convert letters to numbers in javascript. For more information, please follow other related articles on the PHP Chinese website!