Currently, I am dealing with a JSON object that contains over 250 arrays. Each array holds data related to various countries such as population, language, and currency. My objective is to extract a specific key-value pair (country code) from each array and store it in a different variable for future use.
Although I attempted to utilize the forEach method for this task, my lack of experience with it hindered my progress. Upon researching similar inquiries online, I noticed that most people were seeking guidance on iterating through all key/value pairs, rather than extracting a particular one like in my scenario.
$.getJSON("https://restcountries.eu/rest/v2/all", function(callback) {
var isoCode = callback[5].alpha2Code;
console.log(isoCode);
});
The provided code successfully retrieves the alpha2code (country code) for a specific array ([5] in this instance). While this meets the desired outcome, I now seek a way to automate the process so it iterates through all 250 arrays, extracts all country codes, and stores them in individual variables.