I have the following data structure:
var map_neighbours = [{
"Alaska": ["UstKamchatsk", "Yukon"]
}, {
"Algeria": ["Chad", "Egypt", "SierraLeone", "Spain"]
}, {
"AntarticWildlifeTerritory": ["AustralianAntarticTerritory", "SouthAfricanAntarticTerritory"]
}, .....]
The user selects a region via the page, I want to loop through this structure, find the region, then loop through the sub-regions (in the corresponding position).
So for example, for Algeria I want to get "Chad", "Egypt", "SierraLeone", "Spain" one by one out of a loop.
I have tried a few variation of this without success (region is supplied by the user as mentioned above):
var neighbourArray = map_neighbours[region];
$.each(neighbourArray, function(idx, val) {
console.log("Neighbours= " + neighbourArray[region][idx]);
});
or
$.each(map_neighbours, function(outer, val) {
if (map_neighbours[outer] == region) {
neighbourArray = (map_neighbours[outer][]);
$.each(neighbourArray, function(inner, val) {
console.log("Neighbours= " + neighbourArray[outer][inner]);
});
);
};
Thanks for any advice.
= >supposed to be there, or is it supposed to be a:?