How to get the ASCII value in JavaScript for the characters

JavascriptCharAscii

Javascript Problem Overview


> 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?

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

you can try

"str".charCodeAt(0)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnand MuruganView Question on Stackoverflow
Solution 1 - JavascriptiosebView Answer on Stackoverflow
Solution 2 - JavascriptNikson Kanti PaulView Answer on Stackoverflow