Is there a way to dynamically replace the key "Argentina" in a JSON object with a javascript variable string?
jQuery(document).ready(function() {
$.getJSON('countries.json', function(data) {
var output= data.Argentina[0].countryPhone1;
alert(output);
});
});
Shown below is an excerpt of the .json file I am working with:
{
"Argentina": [{
"countryName":"Argentina",
"countryPhone1":"1234"
}],
"Brazil": [{
"countryName":"Brazil",
"countryPhone1":"5678"
}]
}
I have attempted various solutions suggested here, here, as well as here, but I have yet to find a suitable solution for my specific case.