I have the data in the below format:
[{ Country: 'USA', State: 'CA', City: 'LA', District: 'LA-1',Town: 'LA-1,LA-1a,LA_AZ_A',Area: 'Area 51'},
{ Country: 'USA', State: 'CA', City: 'LA', District: 'LA-2' },
{ Country: 'USA', State: 'CA', City: 'LA', District: 'LA-3' },
{ Country: 'USA', State: 'CA', City: 'LA', District: 'LA-4' },
{ Country: 'USA', State: 'CA', City: 'LA', District: 'LA-5' },
{ Country: 'USA', State: 'CA', City: 'SJ', District: 'SJ-1' },
{ Country: 'USA', State: 'CA', City: 'SJ', District: 'SJ-2' },
{ Country: 'USA', State: 'CA', City: 'SJ', District: 'SJ-3' },
{ Country: 'USA', State: 'CA', City: 'SJ', District: 'SJ-4' } ]
The last two columns i.e Town and Area are optional.
Based, on this data, how can I create a hierarchy?
The output expected is like this (I have created this in excel just to show the hierarchy that I need but as array/object)
In conclusion, how can I create a hierarchical data structure?
Any help is appreciated. Thank you.