JavaScript: multidimensional Dictionary
Hi all,
I have a problem to get some values from the multidimensional dictionary. I have a dict like this:
{
“Level 1 - A“ : {
“Level 2 - a” : [ 1, 2, 3 ],
“Level 2 - b” : [ 4, 5, 6 ],
“Level 2 - c” : [ 7, 8, 9 ]
}
,
“Level 1 - B” : {
“Level 2 - a” : [ 10, 20, 30 ],
“Level 2 - b” : [ 40, 50, 60 ],
“Level 2 - c” : [ 70, 80, 90 ]
}
,
“Level 1 - C” : {
“Level 2 - a” : [ 100, 200, 300 ],
“Level 2 - b” : [ 400, 500, 600 ],
“Level 2 - c” : [ 700, 800, 900 ]
}
}
I can get the list of the keys via JavaScript by this:
function getKeys () {
var keys = myArray.getkeys();
post (keys);
}
=> “Level 1 - A“, “Level 1 - B“, “Level 1 - C”.
The question is, how can I get the “keys” of the “Level 1 - A” dictionary, please? So my expected result is:
=> “Level 2 - a”, “Level 2 - b”, “Level 2 - c”.
In Max, I can make an object:
[dict.unpack “Level 1 - A“: “Level 1 - B“: “Level 1 - C”:]
But this doesn’t work very well with the spaces, and it’s not so flexible, as I need to. So I would like to write it in the JavaScript.
Thanks!
Here is a link to a discussion with many types of dictionary examples. Perhaps one will help your project.
Also, have you considered working with the data in JSON objects? It can handle multi-level data and according to the docs, JSON is one of the recognized file types in Max(7).
HTH
The link in the previous post seems to be broken, so I repost it here;