-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task 4.2.html
69 lines (53 loc) · 1.78 KB
/
Task 4.2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<head>
<title>Task 4</title>
</head>
<body>
<h3>Task 4</h3>
<script>
function handleData()
{
console.log("Flags of all Countries")
let data = JSON.parse(this.responseText)
// console.log(data)
// for(let i=0;i<data.length;i++)
// {
// console.log(data[i].flags);
// }
// or
for(e in data)
{
console.log(data[e].flags);
}
// or
// for(e of data)
// {
// console.log(e.flags);
// }
console.log("Name, region, subregion, population of all countries")
// for(let i=0;i<data.length;i++)
// {
// console.log(data[i].name, data[i].region, data[i].subregion, data[i].population);
// }
// or
// for(i in data)
// {
// console.log(data[i].name, data[i].region, data[i].subregion, data[i].population);
// }
// or
for(e of data)
{
console.log(e.name, e.region, e.subregion, e.population);
}
}
const req = new XMLHttpRequest();
req.addEventListener('load',handleData)
// req.onload = (res)=>{
// console.log(JSON.parse(res.srcElement.responseText))
// }
req.open("GET","https://restcountries.com/v3.1/all")
req.send()
</script>
</body>
</html>