[Solved] dynamically creating an associative array
This should do the trick: var hash_a = {‘foo’: ‘bar’}; var hash_b = {‘alha’: ‘beta’}; var array = [‘a’, ‘b’, ‘c’]; function build(a,b,c){ var o=c.reduceRight(function(o, n){ var b={}; b[n]=o; return b; }, b); for(x in a){ o[x]=a[x]; } return o; } Here is the fiddle to play with. See MDN for further explanation of Array.prototype.reduceRight(). … Read more