How to iterate through a specific key-value pair in array

I am working with a JSON object that consists of 250+ arrays (data related to different countries, language, currency etc.) I need a particular key-value pair (country code) to be pulled out of each array and stored in a different variable so I could use it for something else later.

I have tried using forEach method but I don't have a lot of experience with it so I haven't succeeded. After googling similar questions I found that people are usually asking how to iterate though all key/value pairs and not a specific one like in this case.


$.getJSON("https://restcountries.eu/rest/v2/all", function(callback) { 
    var isoCode = callback[5].alpha2Code;
    console.log(isoCode);
 });


The code above pulls out the alpha2code (country code) for a specific array ([5] in this example). Which is the goal, but I need to somehow automate the process so it goes through all 250 arrays, pulls all the country codes and stores them in separate variable.



Not the answer you're looking for? Browse other questions tagged javascript json or ask your own question.