-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (26 loc) · 1.06 KB
/
index.ts
File metadata and controls
33 lines (26 loc) · 1.06 KB
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
fetch("https://jsonplaceholder.typicode.com/users").then((data: Response) => {
// console.log(data);
return data.json(); // converting to object
}).then((DataOfObject: {
id: number, name: string, username: string, email: string, // defining array of objects
phone: string, website: string, // same types as in API
company: { name: string, catchPhrase: string, bs: string }
}[]) => {
console.log(DataOfObject[0].id);
let tableData = "";
DataOfObject.map((values) => {
tableData += `<tr>
<td> ${values.id} </td>
<td> ${values.name} </td>
<td> ${values.username} </td>
<td> ${values.email} </td>
<td> ${values.phone} </td>
<td> ${values.website} </td>
<td> ${values.company.name} </td>
<td> ${values.company.catchPhrase} </td>
<td> ${values.company.bs} </td>
</tr>`;
});
document.getElementById("table_body")!.innerHTML = tableData; // used ! because of
// No Null values
})