Reviewing the following JSON response:
[
{"name": "Afghanistan", ...},
{"name": "country 2" ,...},
{"name": "country 3" ,...},
]
My goal is to extract only country names from the array. Can someone advise me on how I can achieve this?
async function fetchData(data, name) {
var x = await fetch("https://restcountries.eu/rest/v2/all");
var data = await x.json();
var countryNames = [];
for (let i = 0; i <= data.length; i++) {
var countryName = data[i].name;
countryNames.push(countryName)
}
console.log(countryNames);
}
fetchData();