how to get alphabet in javascript code example
Example 1: how to make an alphabet in javascript
// To get an array of letters from 'a' to 'z' in javascript.
let alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
Example 2: javascript number in alphabet
// converts numbers to spreadsheet letter columns eg. 1 -> A
function numToSSColumn(num){
let s = '', t;
while (num > 0) {
t = (num - 1) % 26;
s = String.fromCharCode(65 + t) + s;
num = (num - t)/26 | 0;
}
return s || undefined;
}
numToSSColumn(0); // undefined
numToSSColumn(1); // A
numToSSColumn(26); // Z
numToSSColumn(-1); // undefined
numToSSColumn(27); // AA
numToSSColumn(475254); // ZZZZ