thinking_hydrogen thinking_hydrogen - 27 days ago 5x
Javascript Question

Javascript - Associative array with alphabets as keys

I am looking to create a Javascript object (associative array) with alphabets as keys. Your inputs for the best way to accomplish this will be much appreciated.

Example -

obj[a] = 'somevalue'
obj[b] = 'somevalue'
obj[z]= 'some value'

Assigning alphabets as keys dynamically.

Thanks in advance.


Here's a quick and lazy way to create the object:

var a = 97;
var charArray = {};
for (var i = 0; i<26; i++)
    charArray[String.fromCharCode(a + i)] = String.fromCharCode(a + i);