I am trying to build an API with JavaScript to fetch data from this URL for JSON data: img, a, c , but below codes threw back an error of
application.js:10 Uncaught (in promise) TypeError:
data.forEachis not a function
(why is the forEach method not defined) can you help?
var results = document.getElementById("results");
fetch("https://www.mangaeden.com/api/list/0/")
.then(response => response.json())
.then((data) => {
data.forEach((result) => {
const movies = '<li><img src="' + result.im + '" alt=""><h3>' + result.a + '</h3><p>' + result.c + '</p></li>';
results.insertAdjacentHTML("beforeend", movies);
});
});
{
"a": "shoujo-apocalypse-adventure",
"c": [
"Adventure",
"Drama",
"Psychological",
"Sci-fi",
"Seinen",
"Slice of Life",
"Tragedy"
],
"h": 156,
"i": "5c410d31719a16035a4647cc",
"im": "4a/4a1f2a595e0e84e62f6ceddf3946274478928ca99e8df86bc6511b6e.png",
"ld": 1547822837.0,
"s": 2,
"t": "Shoujo Apocalypse Adventure"
},
{ "end": -1, "manga": [ { "a": "joshiraku", "c": [ "Comedy", "Shounen", "Slice of Life" ], "h": 0, "i": "5bfdd0ff719a162b3c196677", "im": "4e/4e55aeda6ba2044eb2762124688b61e74f24880515e71827f1f1e2c4.png", "ld": 1543389646.0, "s": 2, "t": "Joshiraku" }, ]} },at the very end may indicate it is an element of an array. However in that case saying it is "the Json file:" is not entirely correct.