I am doing a project which uses The Movie Db API and I am bit confused with displaying following object:
(3) [{…}, {…}, {…}]
0: {id: 12, name: "Adventure"}
1: {id: 28, name: "Action"}
2: {id: 878, name: "Science Fiction"}
length: 3
__proto__: Array(0)
Basically, I am trying to figure out how to display those 3 genres in one element. Doing forEach loop like this :
const genreArr = data.genres;
console.log(genreArr)
genreArr.forEach(function(item){
genre.textContent = item.name;
})
displays only one name of genre rather than all of them. So, what do I have to do to display all of those in one paragraph?
+=, or better, accumulate a string and then set it once your done to avoid updating the dom multiple times