I would like to map out countries belonging to regional groups (like ‘South Asia’, comprised of India, Bangladesh, Nepal, Bhutan, Sri Lanka and the Maldives)
Now I am stuck on how to filter down the countries to my targets. The identifying information (like country name) are nested pretty far down into the JSON object features. For example:
How then can I filter this object based on values in the ["SOVEREIGNT"] property?
I’ve tried looping through the object key for a match:
{
var x = 0;
for (let i = 0; i <= ne_10m_admin_0_sovereignty.length; i++) {
return ne_10m_admin_0_sovereignty["features"][i]["properties"]["SOVEREIGNT"] == "Indonesia";
}
return x;
}
If you’re not really sure what you’re looking for and you want an overview of the data, I recommend using d3.group and experimenting with different properties that you see on each feature (by inspecting one of the features). For example:
d3.group(ne_10m_admin_0_sovereignty.features, f => f.properties.SUBREGION)
As a bit of follow up: How to go about adding multiple countries?
I note that the natural earth definition of the South Asia region is different than my target group. My attempt at using array find with && and/or ||, however, doesn’t seem to be capturing multiple countries.
i.e. I tried:
ne_10m_admin_0_sovereignty.features.find(f => f.properties.SOVEREIGNT === "India", f => f.properties.SOVEREIGNT === "Bhutan")