-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (23 loc) · 839 Bytes
/
Copy pathtest.js
File metadata and controls
36 lines (23 loc) · 839 Bytes
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
// Define JSON payload
let games = {
"items": [
{ "name": "Magicka", "price": 9.99 },
{ "name": "Dungeon Defenders", "price": 14.99 },
{ "name": "Goat Simulator", "price": 9.99 },
{ "name": "Helldivers 2", "price": 39.99 }
]
}
let jsonString = JSON.stringify(games);
games = JSON.parse(jsonString);
const table = document.getElementById("gamelist-items");
// Loop through all of the items in the JSON and extract the data and put it into a table
for (i in games.items) {
const row = document.createElement("tr");
const cell1 = document.createElement("td")
cell1.textContent = games.items[i].name
row.appendChild(cell1);
const cell2 = document.createElement("td")
cell1.textContent = games.items[i].price
row.appendChild(cell2);
table.appendChild(row);
}