var obj = { };
obj['A'] = 'letter A';
obj['B'] = 'letter B';
obj['C'] = 'letter C';
or:
var obj = [ ];
obj['A'] = 'letter A';
obj['B'] = 'letter B';
obj['C'] = 'letter C';
and then:
alert(obj.B);
or the equivalent:
alert(obj['B']);
I would use the { }
syntax for non-integer based indexes though. Why? Because there are some real gotchas when you use [ ]
with non-integer indexes, like this one:
var obj = [ ];
obj['A'] = 'letter A';
obj['B'] = 'letter B';
obj['C'] = 'letter C';
alert(obj.length);
Guess what will be printed? Yes, you guessed it: 0.