Associative Array In Javascript
http://stackoverflow.com/q/27198974/1144203
HTML
<script src="http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js"></script>
JavaScript
// an array with numeric indices works.
// some_array has 2 entries.
var my_array = new Array()
my_array[0] = 'Test 1'
my_array[1] = 'Test 1'
var my_type = 'My Type 1'
var my_data = {type: my_type, some_array: my_array}
console.log(my_data)
// an array with non-numeric indices doesn't work.
// some_array is an empty array.
var my_array2 = new Array()
my_array2['a'] = 'Test 2'
my_array2['b'] = 'Test 2'
var my_type2 = 'My Type 2'
var my_data2 = {type: my_type2, some_array: my_array2}
console.log(my_data2)
// an array of objects work.
// some_array has 2 entries.
var my_array3 = new Array()
my_array3[0] = {'a': 'Test 3'}
my_array3[1] = {'b': 'Test 3'}
var my_type3 = 'My Type 3'
var my_data3 = {type: my_type3, some_array: my_array3}
console.log(my_data3)
// an object works.
// some_array has 2 entries.
var my_var_obj = {a: 'Test 4', b: 'Test 4'}
var my_type4 = 'My Type 4'
var my_data4 = {type: my_type4, some_array: my_var_obj}
console.log(my_data4)
// a JSON data structure works.
// some_array has 2 entries.
var my_var_obj = $.toJSON({'a': 'Test 5', 'b': 'Test 5'})
var my_type5 = 'My Type 5'
var my_data5 = {type: my_type5, some_array: my_var_obj}
console.log(my_data5)