How to get the ASCII value in JavaScript for the characters [duplicate]

做~自己de王妃 提交于 2019-12-31 11:01:27

问题


Possible Duplicate:
Convert character to ASCII code in Javascript

my requirement is to get the ASCII value of the alphabet letters... Can anyone suggest how to do this in JavaScript?


回答1:


Here is the example:

var charCode = "a".charCodeAt(0);
console.log(charCode);

Or if you have longer strings:

var string = "Some string";

for (var i = 0; i < string.length; i++) {
  console.log(string.charCodeAt(i));
}

String.charCodeAt(x) method will return ASCII character code at a given position.




回答2:


you can try

"str".charCodeAt(0)


来源:https://stackoverflow.com/questions/10879244/how-to-get-the-ascii-value-in-javascript-for-the-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!