How can I loop from A to Z? I\'d like to populate a select menu with the letters of the alphabet, eg
You can avoid having numbers like 65
in your code if you just use charCodeAt()
and fromCharCode()
.
Print letters from a
to z
:
for(let i = 'a'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) {
$('#select_id_or_class').append(
''
);
}
Or:
const aCharCode = 'a'.charCodeAt(0);
for(let i = aCharCode; i <= (aCharCode + 26); i++) {
$('#select_id_or_class').append(
''
);
}
If you want the uppercase characters, replace 'a'.charCodeAt(0)
with 'A'.charCodeAt(0)