Firstly apologies as I am fairly new to fetching from an API and I am trying to learn.
I need to fetch “name” , “age” and “phone” from “id” 1 from “is” and display it when click on button. This is my javascript-fetch-api.js file:
I’m not sure how to fetch only from id 1 “is”
JavaScript
x
54
54
1
const events = [{
2
"id": 1,
3
"language": {
4
"is": {
5
"name": "Ali Sakaroğlu",
6
"age": 27,
7
"phone": "05368218685",
8
"tags": [
9
"Gallery",
10
"STAK",
11
"Gallery Julius",
12
"mom",
13
"young",
14
"lorem",
15
"ipsum",
16
"show",
17
"born",
18
"worm",
19
"dorm",
20
"norm",
21
"dlla"
22
]
23
},
24
"en": {
25
"name": "Ali Sakaroğlus",
26
"age": 27,
27
"phone": "05368218685",
28
"tags": [
29
"Gallery",
30
"STAK",
31
"Gallery Julius",
32
"mom",
33
"young",
34
"lorem",
35
"ipsum",
36
"show",
37
"born",
38
"worm",
39
"dorm",
40
"norm",
41
"dlla"
42
]
43
}
44
}
45
}]
46
47
48
let output = '<ul>';
49
events.forEach((event) => {
50
output += `<li>${event.id}) Name: ${event.name} - Age: ${event.age} - Phone: ${event.phone} </li> `;
51
});
52
53
output += '</ul> <hr>';
54
document.getElementById('output').innerHTML += output;
JavaScript
1
1
1
<div id="output"></div>
Advertisement
Answer
inside event you have id and language, not name, age and phone. if you want to get name, age and phone from “is”, you should type:
JavaScript
1
4
1
event.language.is.age
2
event.language.is.name
3
event.language.is.phone
4