There is the following query results: (key1 and key2 could be any text)
id key1 key2 value
1 fred apple 2
2 mary orange 10
3 fred banana 7
4 fred orange 4
5 sarah melon 5
...
and I wish to store the data in a grid (maybe as an array) looping all the records like this:
apple orange banana melon
fred 2 4 7 -
mary - 10 - -
sarah - - - 5
In PHP this would be really easy, using associative arrays:
$result['fred']['apple'] = 2;
But in JavaScript associative arrays like this doesn't work. After reading tons of tutorial, all I could get was this:
arr=[];
arr[1]['apple'] = 2;
but arr['fred']['apple'] = 2;
doesn't work.
I tried arrays of objects, but objects properties can't be free text.
The more I was reading tutorials, the more I got confused...
Any idea is welcome :)
var grid = {};grid['aa']['bb'] = 1;
returns "Uncaught TypeError: Cannot set property 'bb' of undefined". I could be wrong, but with most of your examples I have to know the data at initialization time.var grid = {}; grid['aa'] = {}; grid['aa']['bb'] = 1;
works. A more complex test fails, but looks like I'm in the right path