string to alphabet number javascript code example
Example 1: how to make an alphabet in javascript
let alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
Example 2: javascript alphabet to number
function convertLetterToNumber(str) {
str = str.toUpperCase();
let out = 0, len = str.length;
for (pos = 0; pos < len; pos++) {
out += (str.charCodeAt(pos) - 64) * Math.pow(26, len - pos - 1);
}
return out;
}
convertLetterToNumber("A");
convertLetterToNumber("b");
convertLetterToNumber("Ba");
convertLetterToNumber("dE");
convertLetterToNumber("ZZZZ");