I am trying to pull some data from this website by referring to their documentation at https://dog.ceo/dog-api/documentation/
I am trying to retrieve the list of dog breeds and create a list. I am using javaScript's "fetch"
let dog_list = [];
fetch('https://dog.ceo/api/breeds/list/all')
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error(response.statusText);
}
})
.then(data => dog_list = data.message)
const container = document.getElementById("container");
for (dog in dog_list) {
let li = document.createElement("li");
let node = document.createTextNode(dog);
li.appendChild(node);
container.appendChild(li);
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dog Breed List</title>
</head>
<body>
<ul id="container"></ul>
<script src="dog_breed.js"></script>
</body>
</html>
I am having issues at the second "then" where I have no idea on how to convert the json object into array and display them as
- dog1
- dog2
- dog3