check this json response is
[
{"name": "Afghanistan", ...},
{"name": "country 2" ,...},
{"name": "country 3" ,...},
]
Likewise
I want only country name in array
please suggest me how can I get only country name.
async function fetchval(data, name) {
var x = await fetch("https://restcountries.eu/rest/v2/all");
var data = await x.json();
// console.log(data)
var tt = [];
for (let i = 0; i <= data.length; i++) {
var xs = data[i].name; //somtime it gives error that name is undefined.
// console.log(xs);
tt.push(xs)
}
console.log(tt); **i can not log out side the for loop**
}
fetchval();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…