If you want to be able to handle Excel like letters past 26 like AA
then you can use the following function adapted from this question:
<!-- language: lang-js -->
function convertLetterToNumber(str) {
var out = 0, len = str.length;
for (pos = 0; pos < len; pos++) {
out += (str.charCodeAt(pos) - 64) * Math.pow(26, len - pos - 1);
}
return out;
}
###Demo in Stack Snippets:
<!-- begin snippet: js hide: true -->
<!-- language: lang-js -->
function convertLetterToNumber(str) {
var out = 0, len = str.length;
for (pos = 0; pos < len; pos++) {
out += (str.charCodeAt(pos) - 64) * Math.pow(26, len - pos - 1);
}
return out;
}
var testCase = ["A","B","C","Z","AA","AB","BY"];
var converted = testCase.map(function(obj) {
return {
letter: obj,
number: convertLetterToNumber(obj)
};
});
console.table(converted);
<!-- end snippet -->