I'm doing a Javascript exercise and I'm trying to display specific data using a fetch request.
I'm trying to display the data from title and body from the api url. I keep on getting undefined for some reason when I'm fetching for body and title data.
How do I do display the data from body and title correctly that with my current JS code?
Any help is appreciated, thanks!
Javascript:
fetch('https://uqnzta2geb.execute-api.us-east-1.amazonaws.com/default/FrontEndCodeChallenge')
.then(function (response) {
return response.json();
})
.then(function (data) {
appendData(data);
})
.catch(function (err) {
console.log('This is an error');
});
function appendData(data) {
let mainContainer = document.getElementById("testdata");
for (var i = 0; i < data.length; i++) {
var div = document.createElement("div");
div.innerHTML = 'Name: ' + data[i].id + ' ' + data[i].body;
mainContainer.appendChild(div);
}
}
bodyandtitleare inside theversionContentproperty (which is an array) ... i.e.data[i].versionContent[0].bodywhere0always exxists, but in some cases you also have1and even2- did you want all versions or just the latest?