Skip to content

Instantly share code, notes, and snippets.

@bendc
Created January 30, 2015 21:38
Show Gist options
  • Save bendc/1e6af8f2d8027f2965da to your computer and use it in GitHub Desktop.
Save bendc/1e6af8f2d8027f2965da to your computer and use it in GitHub Desktop.
Array of uppercase and lowercase letters
const letters = (() => {
const caps = [...Array(26)].map((val, i) => String.fromCharCode(i + 65));
return caps.concat(caps.map(letter => letter.toLowerCase()));
})();
@AxizY
Copy link

AxizY commented Mar 26, 2020

@kwiniarski97

Savior

@taherkheli
Copy link

Brilliant :). Thanks

@hng12
Copy link

hng12 commented May 26, 2020

amazing, tysm

@Ryanarg
Copy link

Ryanarg commented Jun 9, 2020

@kwiniarski97
God bless you

@sunwicked
Copy link

Take my money!

@Midoukh
Copy link

Midoukh commented Dec 17, 2020

The hero we don't deserve

@kananlanginhooper
Copy link

kananlanginhooper commented Dec 29, 2020

da real MVP!

@Kendrip
Copy link

Kendrip commented Feb 6, 2021

WorldWide Legend

@Asol-Nusu
Copy link

Java:
char[] uppercaseAlphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

@duch512
Copy link

duch512 commented Feb 19, 2021

As we speak about JavaScript, SlexAxton anwer is the best, coz strings act like arrays in JavaScript, so you can do:

const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

const letter = letters[0]; // "A"
const randomLetter = letters[Math.floor(Math.random() * letters.length)]; // random letter ;)

They act like arrays thank to temporary object created upon this methods use. You may consider performance issues in some cases.

@buzink
Copy link

buzink commented Feb 26, 2021

["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

thanks!

@MutantRabbit767
Copy link

["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

god bless america

@372027433
Copy link

characters type of this array for java, C, C++ fans
{
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
};

@brianangulo
Copy link

if yall need it with 0-9 added: [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ]

@tbegush
Copy link

tbegush commented May 20, 2021

var specials = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+", "-", ".", "`", "~", "|", "<", ">", "=", "-", "_"]

@image72
Copy link

image72 commented Jun 25, 2021

String.fromCharCode(...Array(123).keys()).slice(97)

@TowhidKashem
Copy link

Just leaving this here if anyone needs...

const alphabet = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
  e: 4,
  f: 5,
  g: 6,
  h: 7,
  i: 8,
  j: 9,
  k: 10,
  l: 11,
  m: 12,
  n: 13,
  o: 14,
  p: 15,
  q: 16,
  r: 17,
  s: 18,
  t: 19,
  u: 20,
  v: 21,
  w: 22,
  x: 23,
  y: 24,
  z: 25,
};

@MutantRabbit767
Copy link

Just leaving this here if anyone needs...

const alphabet = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
  e: 4,
  f: 5,
  g: 6,
  h: 7,
  i: 8,
  j: 9,
  k: 10,
  l: 11,
  m: 12,
  n: 13,
  o: 14,
  p: 15,
  q: 16,
  r: 17,
  s: 18,
  t: 19,
  u: 20,
  v: 21,
  w: 22,
  x: 23,
  y: 24,
  z: 25,
};

If this was an array anybody could get the infexOf any character they want.

@stuart-rickard
Copy link

stuart-rickard commented Nov 20, 2021

const lowerCaseLetters = ['a', 'b','c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's','t', 'u', 'v', 'w', 'x', 'y', 'z'];
const upperCaseLetters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
const numbersZeroToNine = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const selectedSpecialCharacters = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '-', '.', '~', '|', '<', '>', '=', '-', '_', '/', ':', ';', '?', '[', ']', '{', '}', '~'];

see also https://owasp.org/www-community/password-special-characters for a longer list of special characters (including ", ', `, \, and space)

@TowhidKashem
Copy link

Just leaving this here if anyone needs...

const alphabet = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
  e: 4,
  f: 5,
  g: 6,
  h: 7,
  i: 8,
  j: 9,
  k: 10,
  l: 11,
  m: 12,
  n: 13,
  o: 14,
  p: 15,
  q: 16,
  r: 17,
  s: 18,
  t: 19,
  u: 20,
  v: 21,
  w: 22,
  x: 23,
  y: 24,
  z: 25,
};

If this was an array anybody could get the infexOf any character they want.

True but that wouldn't be as efficient as an O(1) lookup as is the case with an object. I used the above in a leetcode problem so time complexity was a concern.

@MutantRabbit767
Copy link

Just leaving this here if anyone needs...

const alphabet = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
  e: 4,
  f: 5,
  g: 6,
  h: 7,
  i: 8,
  j: 9,
  k: 10,
  l: 11,
  m: 12,
  n: 13,
  o: 14,
  p: 15,
  q: 16,
  r: 17,
  s: 18,
  t: 19,
  u: 20,
  v: 21,
  w: 22,
  x: 23,
  y: 24,
  z: 25,
};

If this was an array anybody could get the infexOf any character they want.

True but that wouldn't be as efficient as an O(1) lookup as is the case with an object. I used the above in a leetcode problem so time complexity was a concern.

in what case would you need to get the indexOf a character if your using an object anyways?

@TowhidKashem
Copy link

Just leaving this here if anyone needs...

const alphabet = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
  e: 4,
  f: 5,
  g: 6,
  h: 7,
  i: 8,
  j: 9,
  k: 10,
  l: 11,
  m: 12,
  n: 13,
  o: 14,
  p: 15,
  q: 16,
  r: 17,
  s: 18,
  t: 19,
  u: 20,
  v: 21,
  w: 22,
  x: 23,
  y: 24,
  z: 25,
};

If this was an array anybody could get the infexOf any character they want.

True but that wouldn't be as efficient as an O(1) lookup as is the case with an object. I used the above in a leetcode problem so time complexity was a concern.

in what case would you need to get the indexOf a character if your using an object anyways?

Plenty of string problems on Leetcode has this need. Although for most it would be starting at 1 not 0 like the original snippet I posted. Anyway since then I found a easier way to do this:

// If you need to map alphabets to their corresponding index
"a".charCodeAt() - 96; // 1
"z".charCodeAt() - 96; // 26

@MutantRabbit767
Copy link

Just leaving this here if anyone needs...

const alphabet = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
  e: 4,
  f: 5,
  g: 6,
  h: 7,
  i: 8,
  j: 9,
  k: 10,
  l: 11,
  m: 12,
  n: 13,
  o: 14,
  p: 15,
  q: 16,
  r: 17,
  s: 18,
  t: 19,
  u: 20,
  v: 21,
  w: 22,
  x: 23,
  y: 24,
  z: 25,
};

If this was an array anybody could get the infexOf any character they want.

True but that wouldn't be as efficient as an O(1) lookup as is the case with an object. I used the above in a leetcode problem so time complexity was a concern.

in what case would you need to get the indexOf a character if your using an object anyways?

Plenty of string problems on Leetcode has this need. Although for most it would be starting at 1 not 0 like the original snippet I posted. Anyway since then I found a easier way to do this:

// If you need to map alphabets to their corresponding index
"a".charCodeAt() - 96; // 1
"z".charCodeAt() - 96; // 26

interesting thanks

@JagpreetGrewal
Copy link

JagpreetGrewal commented Dec 3, 2021

std::map<std::string,int> cc_map {{"A",0}, {"B",0}, {"C",0}, {"D",0}, {"E",0}, {"F",0}, {"G",0}, {"H",0}, {"I",0}, {"J",0}, {"K",0}, {"L",0}, {"M",0},
                              {"N",0}, {"O",0}, {"P",0}, {"Q",0}, {"R",0}, {"S",0}, {"T",0}, {"U",0}, {"V",0}, {"W",0}, {"X",0}, {"Y",0}, {"Z",0}, 
                              {"a",0}, {"b",0}, {"c",0}, {"d",0}, {"e",0}, {"f",0}, {"g",0}, {"h",0}, {"i",0}, {"j",0}, {"k",0}, {"l",0}, {"m",0},
                              {"n",0}, {"o",0}, {"p",0}, {"q",0}, {"r",0}, {"s",0}, {"t",0}, {"u",0}, {"v",0}, {"w",0}, {"x",0}, {"y",0}, {"z",0},
                              {"0",0},{"1",0},{"2",0},{"3",0},{"4",0},{"5",0},{"6",0},{"7",0},{"8",0},{"9",0},
                              {"!",0}, {"@",0}, {"#",0}, {"$",0}, {"%",0}, {"^",0}, {"&",0}, {"*",0}, {"(",0}, {")",0}, {"+",0}, {"-",0}, {".",0},
                              {"~",0}, {"|",0}, {"<",0}, {">",0}, {"=",0}, {"-",0}, {"_",0}, {"/",0}, {":",0}, {";",0}, {"?",0}, {"[",0}, {"]",0}, 
                              {"{",0}, {"}",0}, {"~",0},};

leaving this here in case anyone else needs this.

@CrijnWijers
Copy link

["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

exactly what I needed Thx

@DevManFitz
Copy link

["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

W mans

@ianlaurindotolotti
Copy link

Legend

@fwextensions
Copy link

In case anyone needs the full set of lower and upper case Latin characters (all of the various accented versions), built from this table:

const lowercaseString = "abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźżžƃƅƈƌƒƙơƣƥƨƭưƴƶƹƽdžljnjǎǐǒǔǖǘǚǜǟǡǣǥǧǩǫǭǯdzǵǻǽǿȁȃȅȇȉȋȍȏȑȓȕȗɓɔɗɘəɛɠɣɨɩɯɲɵʃʈʊʋʒḁḃḅḇḉḋḍḏḑḓḕḗḙḛḝḟḡḣḥḧḩḫḭḯḱḳḵḷḹḻḽḿṁṃṅṇṉṋṍṏṑṓṕṗṙṛṝṟṡṣṥṧṩṫṭṯṱṳṵṷṹṻṽṿẁẃẅẇẉẋẍẏẑẓẕạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ";
const lowercaseChars = [...lowercaseString];
const uppercaseChars = [...lowercaseString.toLocaleUpperCase()];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment