I have a JSON object with 12 arrays. Different regions of countries. I'm trying to merge this array into select dropdown menu. The JSON looks like this:
"latinamerica": [
"Argentina",
"Bolivia",
"Brazil",
"Chile",
"Colombia",
"Ecuador",
"Paraguay",
"Peru"
],
"korea": ["South Korea"]
Then I call in the JSON with:
$.getJSON('js/countries.json', function(data) {
var items = [];
items[0] = '<option value="0">Country</option>';
$.each(data['latinamerica'], function(key, val) {
items.push('<option value="'+ key +'">'+ val +'</option>');
});
});
Doing this for every array in the Object. Problem is I want to merge all these arrays, sort them alphabetically but still maintain what region they are associated with. So essentially I would have a dropdown of all the countries and the HTML would look like:
<option value="latinamerica">Argentina</option>
<option value="europe">Austria</option>
I've tried doing concat but then I lose my array names. Suggestions? TIA.