I'm making a chart where if person visits a country in a region (in this case Asia), make the bar a certain color.
if (
d.visitCountry === "China" || d.visitCountry === "Japan" ||
d.visitCountry === "Afghanistan" || d.visitCountry === "Armenia" ||
d.visitCountry === "Azerbaijan" || d.visitCountry === "Bangladesh" ||
d.visitCountry === "Bhutan" || d.visitCountry === "Brunei Darussalam" ||
d.visitCountry === "Cambodia" || d.visitCountry === "Georgia" ||
d.visitCountry === "Hong Kong" || d.visitCountry === "India" ||
d.visitCountry === "Indonesia" || d.visitCountry === "Kazakhstan" ||
d.visitCountry === "North Korea" || d.visitCountry === "South Korea" ||
d.visitCountry === "Kyrgyzstan" || d.visitCountry === "Laos" ||
d.visitCountry === "Macau" || d.visitCountry === "Malaysia" ||
d.visitCountry === "Maldives" || d.visitCountry === "Mongolia" ||
d.visitCountry === "Myanmar" || d.visitCountry === "Nepal" ||
d.visitCountry === "Pakistan" || d.visitCountry === "Singapore" ||
d.visitCountry === "Sri Lanka" || d.visitCountry === "Taiwan" ||
d.visitCountry === "Tajikistan" || d.visitCountry === "Thailand" ||
d.visitCountry === "Timor Leste" || d.visitCountry === "Turkmenistan" ||
d.visitCountry === "Uzbekistan" || d.visitCountry === "Vietnam") {
returnColor = "red";
}
The problem with this method I'm using is it's long and tedious.
Is there any way to make it so it's something like this
var worldRegion = {
worldRegion.Asia = [ China, Japan, North Korea ... ]
worldRegion.northAmerica = [USA, Canada, Greenland ... ]
worldRegion.Africa = [ ... ]
if (d.visitCountry === worldRegion.Asia) /* this is obviously wrong */ {
returnColor = "red";
}
else if (d.visitCountry === worldRegion.northAmerica) /* this is obviously wrong */ {
returnColor = "blue";
}
return returnColor;
Obviously that code is wrong though.