-2

Possible Duplicate:
Convert character to ASCII code in Javascript

How can I convert any character to the key code like

m    77
n    78
o    79
p    80
q    81
r    82
s    83
t    84
u    85
v    86
1
  • 1
    character.charCodeAt(0) - 32 Commented Nov 6, 2012 at 2:30

1 Answer 1

1
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''),
    len = alphabet.length,
    i;

for (i = 0; i < len; ++i) {
    console.log(alphabet[i], alphabet[i].charCodeAt(0) - 32);
}

http://jsfiddle.net/zerkms/n2ZFa/

Sign up to request clarification or add additional context in comments.

1 Comment

'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(c){console.log(c.charCodeAt(0))});

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.