Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript alphabet to number

/**
 * Converts a spreadsheet column letter to a number. eg. A -> 1
 * 
 * @param {String} str - (required) The spreadsheet column letter to convert to a number.
 * 
 * @returns {(Number|undefined)} The column number or undefined.
 */
function convertLetterToNumber(str) {
  if ((typeof str === "string" || str instanceof String) && /^[a-zA-Z]+$/.test(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;
  } else {
    return undefined;
  }
}

convertLetterToNumber("A"); // 1
convertLetterToNumber("b"); // 2
convertLetterToNumber("Ba"); // 53
convertLetterToNumber("dE"); // 109
convertLetterToNumber("ZZZZ"); // 475254

convertLetterToNumber("A"); // 1
convertLetterToNumber("b"); // 2
convertLetterToNumber("Ba"); // 53
convertLetterToNumber("dE"); // 109
convertLetterToNumber("ZZZZ"); // 475254
Comment

js int to alphabet

var value = 10;

document.write((value + 9).toString(36).toUpperCase());
Comment

alphabet to number javascript

str = 'z'
n = (str == str.toLowerCase()) ? 96 : 64
result = str.charCodeAt(0) - n
console.log(result);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check object methods 
Javascript :: jquery each array object 
Javascript :: ajax data and image upload laravel 
Javascript :: jquery copy all options from select to another 
Javascript :: js array intersection object 
Javascript :: access laravel eloquent relation in js 
Javascript :: javascript check collision 
Javascript :: vim react snippets 
Javascript :: sweetalert angular 8 
Javascript :: javascript remove period from end of string 
Javascript :: regex for 4 digit number javascript 
Javascript :: defer parsing of javascript wordpress 
Javascript :: nextjs socket.io 
Javascript :: javascript add spaces to string 
Javascript :: Form.Control textarea react bootstrap 
Javascript :: express js redirect to url 
Javascript :: javascript redirect another page 
Javascript :: converst strig in number in js 
Javascript :: puppeteer stealth 
Javascript :: check if string contains word nodejs 
Javascript :: how to show only time in hours and minutes only in javascript 
Javascript :: node js get ip 
Javascript :: JavaScript - How to get the extension of a filename 
Javascript :: regex match entire words only js 
Javascript :: username validation formik react yup 
Javascript :: get only day from date in javascript 
Javascript :: jquery ajax while loading 
Javascript :: react redirect to url 
Javascript :: oncheck checkbox javascript 
Javascript :: javascript object dont sort 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =