Assume that I need a JavaScript dictionary (object/ associative array) which I need to access as follows:
var value = dict[foo][bar][buz][qux]; // this could go on
Which is the best way to initialize this dictionary? The only way I can think of is:
// 'foo', 'bar', 'baz', 'qux' are variables
var dict = {};
dict[foo] = {};
dict[foo][bar] = {};
dict[foo][bar][buz] = {};
dict[foo][bar][buz][qux] = value;
Alternatively, is there a better way of achieving the same results? I would prefer a solution that works both in browsers and Node.js.