Answers for "string to alphabet number javascript"

4

how to make an alphabet in javascript

// To get an array of letters from 'a' to 'z' in javascript.

let alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
Posted by: Guest on October-25-2020
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"); // 1
convertLetterToNumber("b"); // 2
convertLetterToNumber("Ba"); // 53
convertLetterToNumber("dE"); // 109
convertLetterToNumber("ZZZZ"); // 475254
Posted by: Guest on January-12-2021

Code answers related to "string to alphabet number javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language