I have a JSON object with 12 arrays. Different regions of the countries. I am trying to combine this array into a dropdown menu. JSON looks like this:
"latinamerica": [ "Argentina", "Bolivia", "Brazil", "Chile", "Colombia", "Ecuador", "Paraguay", "Peru" ], "korea": ["South Korea"]
Then I call in 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 each array in the object. The problem is that I want to combine all these arrays, sort them in alphabetical order, but at the same time save what area they are associated with. Therefore, in essence, I would have had the fall of all countries, and the HTML would have looked like this:
<option value="latinamerica">Argentina</option> <option value="europe">Austria</option>
I tried doing concat, but then I lose the array names. Suggestions? TIA.
source share