Alphabet

Made for http://stackoverflow.com/questions/39268764/fill-a-div-container-with-the-alphabet-with-jquery

by Cristian González

HTML

<div class="letters">
</div>

JavaScript

// Let's build a function for building the alphabet array
function getAlphabet(first, last) {
	var alphabet = [];
  
  for (i = first.charCodeAt(0); i <= last.charCodeAt(0); ++i) {
  	alphabet.push(String.fromCharCode(i));
	}
	
  return alphabet;
}

// Calling the function
var alphabet = getAlphabet('A', 'Z'); // ["a", ..., "z"]

// Printing the array inside the .letters element
$.each(alphabet, function (index, element) {
	$(".letters").append("<div>" + element + "</div>");
});