Im trying to get all the messages from a facebook group post to display. with the code below:
FB.api("/groupid/feed", function (response) {
console.log(i + " : " + response.data.length);
for (var i = 0; i < response.data.length; i++) {
console.log(i + " : " + response.data[i].message);
document.getElementById('posts').innerHTML = 'post: ' + i + ' : ' + response.data[i].message +'</br>';
}
}) ;
I cant get the information in getElementId to show all the information that the console log shows. The console log shows 24 items and the website will just display 1 item. What do i need to change to get the information to display all 24 items not just the first one?
You are overwriting the innerHTML property in that for loop.
Instead, you should be appending it to the innerHTML.
Try this:
While you're at it, you can also refactor the loop entirely to use the native
.forEach
method.It'll be cleaner, take a look: