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>
Use char codes: JavaScript char Codes
for (var i = 65; i <= 90; i++) { $('#select_id_or_class').append('<option>' + String.fromCharCode(i) + '</option>'); }
You can do it with the following
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); $.each(alphabet, function(letter) { $('.example-select-menu').append($('<option>' + alphabet[letter] + '</option>')); });
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(); }