-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task 3.2.html
51 lines (41 loc) · 931 Bytes
/
Task 3.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task 3</title>
</head>
<body>
<h2>TASK 3 - JSON ITERATION</h2>
<script>
function handleData(){
let data = JSON.parse(this.responseText)
// console.log(data)
for(let i=0;i<data.length;i++)
{
console.log(data[i].name.common,data[i].population)
}
for(i in data)
{
console.log(data[i].name.common)
}
for(e of data)
{
console.log(e.name.common,e.population)
}
// forEach
data.forEach((e)=>{
console.log(e.name.common);
})
}
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>