-
Notifications
You must be signed in to change notification settings - Fork 0
/
ind.html
76 lines (66 loc) · 2.25 KB
/
ind.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
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<title>Guvi JS Day 3</title>
</head>
<body>
<h1>Hello</h1>
<h2>This is an example for XML HTTP Request</h2>
<script>
console.log("Welcome to HTML JS")
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)
// }
// MAP FUNCTION
let country= data.map((e)=>e.name.common)
// or
// let country = data.map((e)=>{
// return e.name.common
// })
// let country= data.map((e)=>`${e.name.common}-${e.population}`)
console.log(country);
// FILTER FUNCTION
// let country = data.filter((e)=>e.continents[0]=="North America")
// or
// let country = data.filter((e)=>{
// if(e.continents[0]=="North America")
// {
// return true;
// } else{
// return false;
// }
// })
// console.log(country);
// REDUCE FUNCTION
// let a=[1,2,3,4,5]
// let sum = a.reduce((accumulator,currentvalue)=>{
// // return accumulator+currentvalue
// return accumulator*currentvalue
// } )
// console.log(sum);
}
// {
// console.log(JSON.parse(this.responseText))
// }
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>