JavaScript for WordPress › Forums › Vanilla JavaScript › is for loop better than for of ? › Reply To: is for loop better than for of ?
April 15, 2017 at 6:17 pm
#25770
Alexandra
Participant
in the functions i have tried to put in instead of of
view.loadBlogPosts = function () {
var posts = model.getPosts(),
postsMarkup = document.createDocumentFragment(),
primaryContentEl = helpers.getPageContentEl();
for (var post in posts) {
postsMarkup.appendChild(view.createPostMarkup(post));
}
primaryContentEl.appendChild(postsMarkup);
};
And it doesn’t work , title and content are displayed as undefined, why ?