I have a JavaScript layer for my HTML which has its first 3 rows presented below:
var TR_Accomodation = {
'Hacı Sabancı': {
'İl': 'ADANA',
'Dist': 100,
'Accomodation_Type': 'hotel',
'Count': 52
},
'Ceyhan': {
'İl': 'ADANA',
'Dist': 100,
'Accomodation_Type': 'motel',
'Count': 25
},
'Ceyhan': {
'İl': 'ADANA',
'Dist': 50,
'Accomodation_Type': 'hotel',
'Count': 31
}, ...
dataset has 8000 rows, 81 distinct values for "İl", 4 for "Dist" and 6 in my html I have a listener by drop down list to get İl values and the second one to get the features ‘Ceyhan’ so on.
How can I get the values for each dist value and each Accomodation_Type.
In detail, I want to have variables like Dist_50km_hotel so that presents the e.g. number of hotels at most distance of 50 km of Ceyhan.
How can I extract Count value for feature Ceyhan where the "Dist" is 50 and ‘Accomodation_Type’ is equal to "hotel" and save that in a new variable.
2
Answers
You need to convert it to an array using Object Entries. That will let you filter it based on the object. After that you convert it back to your object format.
You should convert your structure to an array since an object cannot have the same 2 keys: