Duplicates When Iterating Loop In Jade

- 1 answer

I have an array, globally defined in my Node.js app index, app.js like

posts = [];

this array is filled with blocks of html, and if I loop the array in my index, I get the following (currently only filled with one block)

for(var i in posts) console.log(posts[i]);

<h1 id="this-is-ma-title">this is ma title</h1>
<p>hello <strong>123</strong></p>

this is the expected result. When I try to print out this array in the view model however, like this

extends layout
block content

the content seems to duplicate, and also contains random < > notation in the client browser

<div class="post"><<h1 id="this-is-ma-title">this is ma title</h1>
<p>hello <strong>123</strong></p>
></<h1 id="this-is-ma-title">this is ma title</h1>
<p>hello <strong>123</strong></p>

I have tried various differentiations of the loop notation, like

each item in posts


- for (var i=0; i<posts.length; i++) {
- }

but all produce similar results.. am I missing something?



Issue came with the fact the code buffered by = is escaped by default for security, however to output unescaped return values you can use !=

So a solution to this would be:

each item in posts
  p!= item