I have a JSON dataset where each key is represented as a column in a table. I am looking to populate each column with data from the JSON as select boxes. For example, I want to display all "country" values from the JSON as select options in the COUNTRY column.
Sample JSON data
"book": [
{
"author": "Chinua Achebe",
"country": "Nigeria",
"imageLink": "images/things-fall-apart.jpg",
"language": "English",
"link": "https://en.wikipedia.org/wiki/Things_Fall_Apart\n",
"pages": 209,
"title": "Things Fall Apart",
"year": 1958
},
{
"author": "Hans Christian Andersen",
"country": "Denmark",
"imageLink": "images/fairy-tales.jpg",
"language": "Danish",
"link": "https://en.wikipedia.org/wiki/Fairy_Tales_Told_for_Children._First_Collection.\n",
"pages": 784,
"title": "Fairy tales",
"year": 1836
},
Javascript Code
let table2 = document.getElementById("tr2")
var books = fetch("book.json")
.then(res=> res.json())
.then(data => {for(let key in data ) {
for(value of data[key]) {
select.innerHTML+= `
<td><option value="${value.author}">${value.author}</option></td>
<td><option value="${value.country}">${value.country}</option></td>
`
}
}})
How can I make modifications to this setup?