I have a function that pulls a list of countries from a JSON array
function regionPlanOutput(networkGroupId) {
document.getElementById("country_list").innerHTML = "";
jQuery.ajax({
type: 'GET'
, url: regionApiURL + '/api/v4/networkGroups/' + networkGroupId + '/countries?count=500'
, dataType: 'json'
, success: function (networkGroup) {
jQuery.each(networkGroup.countryList, function (i, countryList) {
var countryName = countryList.name;
var flag = countryList.logoUrl;
var countrycontent = '<li>' + countryName + '</li>';
console.log(countrycontent)
jQuery(countrycontent).appendTo("#country_list");
});
}
});
}
At the moment it just prints the list in the order it pulls them from the array, How do I sort the output alphabetically based on the variable countryName?
success, thatnetworkGroupparameter is already a JavaScript object, not JSON. JSON is a string format, so talking about a JSON array is bad terminology.