I am new to Javascript and I have question very similar to How to combine multiple dictionaries in Javascript?
Except that I want to achieve a nested dictionary.
var dictA = {gender: 'male', age_group: 'young', favourite_band: 'Metallica', number_of_visits: 42};
var dictB = {gender: 'female', age_group: 'old', favourite_band: 'Beatles', number_of_visits: 2};
var dictC = {gender: 'male', age_group: 'young', favourite_band: 'Foo Fighters', number_of_visits: 1};
var dictD = {gender: 'male', age_group: 'old', favourite_band: 'Rolling Stones', number_of_visits: 12};
Expected Outcome:
var result =
{
'male': {
'young': {'Metallica': 42, 'Foo Fighters': 1},
'old': {'Rolling Stones': 12}
},
'female': {'old': {'Beatles': 2}}
}
Possibly there is even one more nested information. Is this somehow achieveable? I appreciate every help!
Edit: that example is only showing how it’s done for one „layer“. How can I for example provide a list of „layer columns“ and achieve what’s done above?