A to Z cycle in jQuery

How can I loop from A to Z? I would like to fill the selection menu with letters of the alphabet, for example

<select> <option>A</option> <option>B</option> <option>C</option> ... <option>Z</option> </select> 
+6
source share
3 answers

Use char codes: JavaScript char Codes

 for (var i = 65; i <= 90; i++) { $('#select_id_or_class').append('<option>' + String.fromCharCode(i) + '</option>'); } 
+17
source

You can do it with the following

  var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); $.each(alphabet, function(letter) { $('.example-select-menu').append($('<option>' + alphabet[letter] + '</option>')); }); 
+4
source

This answer demonstrates the great idea that you don't need a string string. Shortly speaking:

for (i = 65; i <= 90; i++) { arr[i-65] = String.fromCharCode(i).toLowerCase(); }

+4
source

All Articles