Q:

Get index position of an alphabet

In java we can get the index position of an alphabet using below code :
int idx = s.charAt(i) - 97;

Now I am looking for similar code in JavaScript:
var idx = s.charAt(i) - 97;

But in javascript I getting isNaN error message; What is the correct way to do this.

A:

Try with this:
"a".charCodeAt(0) - 97

